带请求登录不知道在哪里发布

2024-09-30 14:15:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我完全无法登录此页面:

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...

我找到了here,但我只得到了400状态。你知道吗

谢谢你的阅读。你知道吗


更新:

另一个问题出现了: 当我试着读这页的时候请求.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...

Tags: thetotexthttpsurlgetherehtml
1条回答
网友
1楼 · 发布于 2024-09-30 14:15:55

此脚本应该可以解决您的问题:

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有关。你知道吗

希望这有帮助

相关问题 更多 >

    热门问题