我完全无法尝试登录此页面:
我已经尝试过此解决方案:
import requests
# Fill in your details here to be posted to the login form.
payload = {
'name': 'username',
'pass': 'password'
}
# Use 'with' to ensure the session context is closed after use.
with requests.Session() as s:
login_url = "https://login.wyborcza.pl/"
p = s.post(login_url, data=payload)
# print the html returned or something more intelligent to see if it's a successful login page.
print p.text
# the authorised request.
r = s.get('A protected web page url')
print r.text
# etc...
我找到了here,但是我只得到了400
的状态。
感谢阅读。
更新:
发生另一个问题: 当我尝试使用request.get()阅读此页面时,我收到一条消息,表明adblocker已打开,并且该页面的内容未加载。但是,如果我尝试在浏览器中访问该页面,则没有问题-所有内容均已加载。
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({
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9,nb;q=0.8",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Content-Length": "101",
"Content-Type": "application/x-www-form-urlencoded",
"Cookie": "SsoSessionPermanent=da7c41fb3ce67a9c36068c8752ecb6f6c595261ec033bef85f5a00a09b992491; _gcl_au=1.1.1603784452.1550874547; __utmc=150475568; __utmz=150475568.1550874547.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _ga=GA1.2.624566896.1550874547; _gid=GA1.2.1373698316.1550874547; _fbp=fb.1.1550874547334.2017607101; __gfp_64b=MOGLe6FatMqipvP6ZL6AdioAq5LZyXL4TZ4CaKZlx8H.U7; customDataLayer_customer=%7B%22state%22%3A%22anonymous%22%2C%22validPeriod%22%3A%22%22%7D; __gads=ID=6024a627e7962b38:T=1550874563:S=ALNI_MY5DVzG-IY0cLZRQFFrv-45kvL9AQ; GazetaPlUser=213A32A242A37k1550874561871; SquidLocalUID=f1b0394447af42427a2985c4; __utma=150475568.624566896.1550874547.1550874547.1550913993.2; __utmb=150475568.0.10.1550913993",
"Host": "login.wyborcza.pl",
"Origin": "http://wyborcza.pl",
"Referer": "http://wyborcza.pl/1,76842,3360710.html",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
})
# the authorised request.
r = s.get('https://wyborcza.pl/1,76842,3360710.html')
print(r.text)
# etc...
答案 0 :(得分:0)
此脚本应该可以解决您的问题:
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
中)和您向POST请求发送的login_url
有关。
希望这会有所帮助