【问题标题】:Page 404 through Python Requests but loads fine through browser通过 Python 请求页面 404,但通过浏览器加载正常
【发布时间】:2021-05-26 13:53:21
【问题描述】:

使用 Python 请求获取页面 404,但我可以通过浏览器访问该页面没有问题。我可以访问与此页面格式完全相同的其他页面,并且它们加载没有问题。

已经尝试过更改标题,但没有成功。

我的代码:

string_page = str(page)
with requests.Session() as s:

    resp = s.get('https://bscscan.com/token/generic-tokentxns2?m=normal&contractAddress=0x470862af0cf8d27ebfe0ff77b0649779c29186db&a=&sid=f58c1cdefacc680b799412c7645ed7f7&p='+string_page)

    page_info = str(resp.text)

print(page_info)

我也尝试过使用 urllib 并且发生了同样的事情

【问题讨论】:

  • 你试过sending an “user-agent” using Requests library in Python吗?也许“用户代理应该被指定为标题中的一个字段。”
  • 您可能需要登录才能访问 URL 中的页面。当您使用 Python 时,它以“访客”身份访问页面。
  • 尝试了标头解决方案。没有运气。
  • 我没有在我的浏览器上登录,它仍然有效
  • 您可能较早登录并且浏览器记住了 cookie,这就是它适合您的原因。但是,您应该分享 url 以获得更准确的建议,而不是像您帖子中损坏的那样。

标签: python web-scraping browser python-requests bscscan


【解决方案1】:

我不确定这是否会解决它,但尝试在标题中添加它可能会起作用

'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'

【讨论】:

  • 是的,已经尝试过了。不幸的是没有运气
猜你喜欢
  • 2014-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-04
  • 2015-08-11
  • 2015-07-25
  • 1970-01-01
  • 2011-11-19
相关资源
最近更新 更多