【问题标题】:Download file using python使用python下载文件
【发布时间】:2017-08-25 17:32:44
【问题描述】:

我正在尝试使用 Python 下载 SWF 文件, 但由于某种原因,每次我使用 urllib.urlretrieve(url,filepathwithname) 或 wget.download(url) 时,它都会说:

File "C:\Users\User-PC\Desktop\check.py", line 3, in <module>
response = 
urllib.urlretrieve('www.domain.com\\folder\\folder\\52sd1399sc2emaple-story-
vthree-f.swf','file.swf')
File "C:\Python27\lib\urllib.py", line 98, in urlretrieve
return opener.retrieve(url, filename, reporthook, data)
File "C:\Python27\lib\urllib.py", line 245, in retrieve
fp = self.open(url, data)
File "C:\Python27\lib\urllib.py", line 213, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 469, in open_file
return self.open_local_file(url)
File "C:\Python27\lib\urllib.py", line 483, in open_local_file
raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] The system cannot find the path specified: 
'www.domain.com\\folder\\folder\\52sd1399sc2emaple-story-vthree-f.swf'

虽然 wget 行在与我的代码不同的文件中运行该行时仍然给出相同的错误(没有该下载行可以完美运行),但它有时确实有效,但 wget 从不与我放置的 swf 链接一起使用.

*注意。我输入的字符串是“www.domain.com\folder\folder\52sd1399sc2emaple-story-vthree-f.swf”,错误包含“www.domain.com\folder\folder\52sd1399sc2emaple-story-vthree-f.swf ”。

请帮忙。

【问题讨论】:

  • 尝试将反斜杠改为正斜杠。
  • @lancew 去过那里,试过了,还是不行 :( 感谢评论!
  • 您能出示一下代码吗?
  • 请向我们展示您的代码。所以我们可以看到它。
  • 您的网络浏览器可能会为您填写 URL 的 http:// 部分,但 urllib 不会。在这种情况下,URL 的协议部分不是可选的(使用正确的斜线也不是可选的)。 Stack Overflow 不允许我在评论中写出你的完整 URL(它说使用 example.com 作为域),但你可以通过自己添加 http:// 来修复它。

标签: python python-2.7 selenium-webdriver python-requests urllib


【解决方案1】:

@Blckknght 你太棒了。这就是问题的全部。感谢所有试图提供帮助的人!

整个问题是 urlretrieve 链接中缺少 http://... 我花了将近 10 个小时尝试使用 wget 和其他方法解决这个问题,而 @Blckknght 刚刚为我解决了这个问题。 =)

祝你一切顺利,有美好的一天 -编码代码。

【讨论】:

    猜你喜欢
    • 2012-12-07
    • 2012-06-15
    • 2020-05-12
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多