下载使用Urllib下载属性的文件

时间:2016-08-11 18:00:33

标签: python urllib

我正在尝试解析网页并下载一系列zip文件夹中的csv文件。当我点击网站上的链接时,我可以毫不费力地下载它。但是每当我将URL粘贴到我的浏览器中时(例如:example.com/file.zip),我都会收到400 Bad Request错误。我不确定,但我推断此问题是由于该链接使用download attribute

而导致的

现在的问题是当我使用urllib.request.urlretrieve下载zip文件时,我不能。我的代码很简单:

# Look to a specific folder in my computer
# Compare the zip files in that folder to the zip files on the website
# What ever is on the website, but not on my local machine 
# is added to a dictionary called remoteFiles

for remoteFile in remoteFiles:
  try:
    filename = ntpath.basename(remoteFile)
    urllib.request.urlretrieve(remoteFile, filename)
    print('finished downloading: ' + filename)
  except Exception as e:
    print('error with file: ' + filename)
    print(e)

Here is a PasteBin link到我的完整.py文件。无论我在哪里运行它都会出错:

  

HTTP错误400:错误请求

0 个答案:

没有答案
相关问题