以下内容适用于99.999%的网站,但随机发现了一个不适用的网站:
import requests
requests.get('http://arboleascity.com',timeout=(5,5),verify=False)
我对这个项目提出了异议。在
https://github.com/requests/requests/issues/4276
有什么建议或想法吗?在
我在concurrent.futures.ThreadPoolExecutor
中运行这个,所以我不想添加一些外部的东西,比如eventlet或signals。但对任何有效的东西都要敞开心扉。在
问题不在于
requests
,而在于您访问特定站点的方式。在也就是说,似乎
http://arboleascity.com
使用User-Agent
头字段来区分浏览器和音乐播放器。在如果使用有效的浏览器签名,它只返回页面HTML(
text/html
)并关闭连接:但是,如果未定义
^{pr2}$User-Agent
(默认值),则站点流二进制内容(audio/aacp
)为~8kbps:或者,with ^{} :
他们都在工作。在
它流一个SHOUTcast流(内容类型:audio/aacp),所以没有超时,只是从不停止流。在
如果需要主页,而不是流,请将User-Agent头设置为类似于浏览器的内容。如果您需要音频流,请使用
stream=True
并迭代内容-在这里,如果需要,您也可以退出。在如果您正在编写scraper,那么在尝试获取分块的响应之前,可能需要检查HEAD请求中的内容类型。在
相关问题 更多 >
编程相关推荐