python 标准库 urllib

urllib.request.urlretrieve(url, filename=None)

将url所指向的网络文件复制到本地。将返回一个tuple,元组()(filename,HTTPMessage),其中filename是下载后的本地文件名,HTTPMessage包含了相关信息。

>>> import urllib
>>> a=urllib.request.urlretrieve('https://github.com/adventuresinML/adventures-in-ml-code/blob/master/tf_word2vec.py','haha')
>>> a
('haha', <http.client.HTTPMessage object at 0x000001F4C1095D30>)
>>> os.listdir()
['.idea', 'haha', 'scratch.py', 'utils.py', 'venv', 'w2v_embed.py', 'word_embedding.py', '__pycache__']
>>> b = a[1]
>>> list(b)
['Server', 'Date', 'Content-Type', 'Transfer-Encoding', 'Connection', 'Status', 'Cache-Control', 'Vary', 'Set-Cookie', 'Set-Cookie', 'Set-Cookie', 'X-Request-Id', 'Strict-Transport-Security', 'X-Frame-Options', 'X-Content-Type-Options', 'X-XSS-Protection', 'Expect-CT', 'Content-Security-Policy', 'X-GitHub-Request-Id']
>>> b['Date']
'Fri, 26 Oct 2018 06:27:04 GMT'

猜你喜欢

转载自blog.csdn.net/yuanjackson/article/details/83380941