我试着从一个特定的网站下载一个excel文件。在我的本地计算机中,它工作得非常好:
>>> r = requests.get('http://www.health.gov.il/PublicationsFiles/IWER01_2004.xls')
>>> r.status_code
200
>>> r.content
b'\xd0\xcf\x11\xe0\xa1\xb1...\x00\x00' # Long binary string
但是当我连接到一个远程ubuntu服务器时,我收到一条与启用cookies/javascript相关的消息。在
^{pr2}$在local上,我从安装了Chrome的MACos上运行(我没有在脚本中使用它,但可能是相关的?),在远程,我在数字海洋上运行ubuntu,没有安装任何GUI浏览器。在
requests
的行为与系统上安装的浏览器无关,它不以任何方式依赖或与它们交互。在这里的问题是,您请求的资源启用了某种“bot缓解”机制来阻止这种访问。它返回一些javascript,其中包含需要评估的逻辑,然后该逻辑的结果将用于附加请求,以“证明”您不是bot。在
幸运的是,这个特定的缓解机制似乎是solved before,我能够利用代码中的挑战解决功能快速地使这个请求生效:
相关问题 更多 >
编程相关推荐