1 回答
TA贡献1946条经验 获得超3个赞
此脚本应该可以解决您的问题:
import requests
# Fill in your details here to be posted to the login form.
payload = {
'username': 'username',
'password': 'password'
}
# Use 'with' to ensure the session context is closed after use.
with requests.Session() as s:
login_url = "https://login.wyborcza.pl/services/ajax/wyborcza/login"
p = s.post(login_url, data=payload)
# print the html returned or something more intelligent to see if it's a successful login page.
cookiesALL = s.cookies.get_dict()
s.headers.update({
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:65.0) Gecko/20100101 Firefox/65.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"DNT": "1",
"Connection": "close",
"Upgrade-Insecure-Requests": "1",
"Cookie":"SsoSessionPermanent={}; GW_SID=220D44FAAD9071FAC49796195720D348.tomwybo17; ag-rd-params=; __gfp_64b=-TURNEDOFF; customDataLayer_customer=%7B%22state%22%3A%22anonymous%22%2C%22validPeriod%22%3A%22%22%7D; bwGuidv2=b952c7409c97c249520c9e8a; SquidLocalUID=3c9df34214b0a589cf4863b7; wyborczaXYZ=test; test=131A251A253A104k1550911251283; bwVisitId=f5a2c74d1ba13dfde8d36c40".format(cookiesALL['SsoSessionPermanent'])
})
# the authorised request.
r = s.get('https://wyborcza.pl/1,76842,3360710.html')
print(r.text)
# etc...
您正在处理的问题与您错误的参数名称(在payloads)以及login_url您向其发送 POST 请求有关。
添加回答
举报