简体   繁体   English

Python 请求行为异常

[英]Python requests acting weirdly

When trying to get html code from link ( https://sourceforge.net/projects/easyminer/files/latest/download ) I'm getting a lot of weird symbols.当试图从链接( https://sourceforge.net/projects/easyminer/files/latest/download )获取 html 代码时,我得到了很多奇怪的符号。

However, it's not happening when trying with other websites.但是,尝试使用其他网站时不会发生这种情况。

Code:代码: 在此处输入图片说明

Console:安慰: 在此处输入图片说明

If you specify a User-Agent as normal browser, sourceforge will return a html page, otherwise a 302 redirect to the binary download link.如果您将User-Agent指定为普通浏览器,sourceforge 将返回一个 html 页面,否则将 302 重定向到二进制下载链接。

>>> r = requests.get("https://sourceforge.net/projects/easyminer/files/latest/download", headers={"User-agent": "Mozilla/5.0"})
>>> r.text[:50]
'<!doctype html>\n<!-- Server: sfs-consume-5 -->\n<ht'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM