Python - Urllib.Request - 更改下载文件的位置

时间:2016-03-14 17:39:07

标签: python urllib

如何选择下载文件的存储位置?我的代码:

import urllib.request
user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'
        headers = {'User-Agent':user_agent,}
        request = urllib.request.Request("http://download.thinkbroadband.com/5MB.zip",None,headers)
        response = urllib.request.urlopen(request)
        data = response.read()

1 个答案:

答案 0 :(得分:1)

你几乎就在那里。所以你有ofile = open(where_you_want_to_store_the_data,"wb") ofile.write(data) ofile.close()

urlretrieve

为了更清洁,您可以使用urlretrieve(url, "/path/to/something.txt")

sapply(values[[1]])