我是新手,但试图从需要登录的网站上抓取数据。尝试打开它时出错。问题似乎出在 cookie 中,它们没有被正确存储?
import requests
from bs4 import BeautifulSoup
from urllib.request import urlopen
from http.cookiejar import CookieJar
import urllib
username = 'xxx'
password = 'xxx'
values = {'email': username, 'password': password}
session = requests.session()
login_url = 'https://login.aripaev.ee/Account/Login?ReturnUrl=%2fOAuth%2fAuthorize%3fclient_id%3dinfopank%26redirect_uri%3dhttps%253A%252F%252Finfopank.ee%252FAccount%252FLogin%253FreturnUrl%253D%25252F%2526returnAsRedirect%253DFalse%26state%3dLjNuwARtELJnVPcF8ka2Jg%26scope%3d%252FUserDataService%252Fjson%252FProfile%2520%252FUserDataService%252Fjson%252FPermissions%2520%252FUserDataService%252Fjson%252FOrders%2520%252FUserDataService%252Fv2%252Fjson%252FProfile%2520%252FUserDataService%252Fv2%252Fjson%252FPermissions%2520%252FUserDataService%252Fv2%252Fjson%252FOrders%26response_type%3dcode&client_id=infopank&redirect_uri=https%3A%2F%2Finfopank.ee%2FAccount%2FLogin%3FreturnUrl%3D%252F%26returnAsRedirect%3DFalse&state=LjNuwARtELJnVPcF8ka2Jg&scope=%2FUserDataService%2Fjson%2FProfile%20%2FUserDataService%2Fjson%2FPermissions%20%2FUserDataService%2Fjson%2FOrders%20%2FUserDataService%2Fv2%2Fjson%2FProfile%20%2FUserDataService%2Fv2%2Fjson%2FPermissions%20%2FUserDataService%2Fv2%2Fjson%2FOrders&response_type=code'
url = 'https://infopank.ee/ettevote/1/'
result = session.get(login_url)
result = session.post(login_url, data = values, headers = dict(referer=login_url))
cookieProcessor = urllib.request.HTTPCookieProcessor()
opener = urllib.request.build_opener(cookieProcessor)
page = urlopen(url)
错误信息:
HTTPError: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
Found
欢迎任何建议 - 谢谢!
相关分类