Urlretrieve 和用户代理?- Python [英] Urlretrieve and User-Agent? - Python
本文介绍了Urlretrieve 和用户代理?- Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用来自 urllib 模块的 urlretrieve.
I'm using urlretrieve from the urllib module.
我似乎找不到如何向我的请求添加用户代理描述.
I cannot seem to find how to add a User-Agent description to my requests.
可以使用 urlretrieve 吗?还是我需要使用其他方法?
Is it possible with urlretrieve? or do I need to use another method?
推荐答案
一、设置版本:
urllib.URLopener.version = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 SE 2.X MetaSr 1.0'
那么:
filename, headers = urllib.urlretrieve(url)
这篇关于Urlretrieve 和用户代理?- Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文