为了账号安全,请及时绑定邮箱和手机立即绑定

使用请求登录 - 不知道在哪里发布

使用请求登录 - 不知道在哪里发布

慕慕森 2021-11-16 16:16:33
我完全无法登录此页面:https://login.wyborcza.pl/我试过这个解决方案: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...我在这里找到的,但我只得到一个400状态。谢谢阅读。更新:出现另一个问题:当我尝试使用 request.get() 在此页面中阅读时,我收到一条消息,提示已启用广告拦截器,但未加载页面内容。但是,如果我尝试在浏览器中访问该页面,则没有问题 - 所有内容都已加载。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()
查看完整描述

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 请求有关。



查看完整回答
反对 回复 2021-11-16
  • 1 回答
  • 0 关注
  • 187 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信