我们要操作的网站是https://login2.scrape.center/
需要的库
import requests
from bs4 import BeautifulSoup
import redis
import re
准备工作
base_url = 'https://login2.scrape.center/'
login_url = 'https://login2.scrape.center/login'
请求头
headers = {
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
}
登陆表单
data = {
'username': 'admin',
'password': 'admin'
}
连接redis数据库
r = redis.Redis(host="127.0.0.1", port=6379, password=None, db=1)
创建一个session对象
session = requests.Session(