Urlretrieve and User-Agent? - Python

后端 未结 4 1163
暖寄归人
暖寄归人 2021-02-05 13:08

I\'m using urlretrieve from the urllib module.

I cannot seem to find how to add a User-Agent description to my requests.


Is it possible with urlretrieve? o

4条回答
  •  一生所求
    2021-02-05 13:47

    I don't think it's possible with urlretrieve - at least not easily. I would propose to create an urllib2.Request object and pass the required headers to it. See

    http://docs.python.org/library/urllib2.html#urllib2.urlopen

    for examples.

提交回复
热议问题