我正在尝试访问https://instacart.com/store/wegmans/storefront进行web抓取,但是当我尝试使用以下代码使用Python的请求登录时:
from requests import session
url = 'https://www.instacart.com'
payload = {
'action': 'submit',
'email': 'my_email@gmail.com',
'password': 'my_password'
}
with session() as c:
c.post(url, data=payload)
response = c.get('https://instacart.com/store/wegmans/storefront')
print(response.headers)
print(response.text)
我会说“非常抱歉”回复.text,如下所示:响应.标题地址:
{'Date': 'Tue, 02 Jul 2019 02:58:57 GMT', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Server': 'nginx', 'Set-Cookie': 'build_sha=8f3eb623f91516ad5369c4c373e577ec406c0fa1;Path=/;', 'Cache-Control': 'no-cache', 'X-Request-Id': 'a13241fe-fdce-4eb5-bfa2-958118c7690c', 'X-Runtime': '0.007429', 'Vary': 'Origin'}
我不知道这是什么意思,但我猜“非常抱歉”是当它无法识别您的POST请求时的自动响应。当我手动登录时,密码和电子邮件就起作用了,我假设'action':'submit'
部分是正确的,因为检查登录按钮会显示它的type=“submit”。你知道吗
我想知道这和instacart.com网站没有指向登录页的url。主页上有一个登录表单,但是你必须点击“已经有帐户了吗?”?在它弹出之前登录。这是问题所在还是我的代码有问题?你知道吗
这似乎适用于登录:
正如@andreilozhkin评论的那样,从Chrome DevTools中,您可以确切地看到传递给POST请求的负载,其中包括“authenticity\u token”。我首先向
http://www.instacart.com
发出GET请求,并在PUT登录请求中使用该令牌。你知道吗希望这有帮助。你知道吗
相关问题 更多 >
编程相关推荐