2013-04-20 1 views
0

특정 위키 피 디아 페이지의 모든 이미지를 다운로드하려고합니다. 프로그램을 실행 한 후 나는이 오류의 원인이 무엇인지에 도움을 주시기 바랍니다 스택위키 피 디아에서 파이썬 스크립트를 통해 이미지를 다운로드하는 중 오류가 발생했습니다.

Image: //upload.wikimedia.org/wikipedia/commons/thumb/0/04/Pune_Montage.JPG/250px-Pune_Montage.JPG 
Traceback (most recent call last): 
    File "download_images.py", line 15, in <module> 
    urlretrieve(image["src"], "/home/mayank/Desktop/test") 
    File "/usr/lib/python2.7/urllib.py", line 93, in urlretrieve 
    return _urlopener.retrieve(url, filename, reporthook, data) 
    File "/usr/lib/python2.7/urllib.py", line 239, in retrieve 
    fp = self.open(url, data) 
    File "/usr/lib/python2.7/urllib.py", line 207, in open 
    return getattr(self, name)(url) 
    File "/usr/lib/python2.7/urllib.py", line 460, in open_file 
    return self.open_ftp(url) 
    File "/usr/lib/python2.7/urllib.py", line 543, in open_ftp 
    ftpwrapper(user, passwd, host, port, dirs) 
    File "/usr/lib/python2.7/urllib.py", line 864, in __init__ 
    self.init() 
    File "/usr/lib/python2.7/urllib.py", line 870, in init 
    self.ftp.connect(self.host, self.port, self.timeout) 
    File "/usr/lib/python2.7/ftplib.py", line 132, in connect 
    self.sock = socket.create_connection((self.host, self.port), self.timeout) 
    File "/usr/lib/python2.7/socket.py", line 571, in create_connection 
    raise err 
IOError: [Errno ftp error] [Errno 111] Connection refused 

을 다음과 같이 오류가 있지만 여기 코드는

from bs4 import BeautifulSoup as bs 
import urllib2 
import urlparse 
from urllib import urlretrieve 

site="http://en.wikipedia.org/wiki/Pune" 
hdr= {'User-Agent': 'Mozilla/5.0'} 
outpath="" 
req = urllib2.Request(site,headers=hdr) 
page = urllib2.urlopen(req) 
soup =bs(page) 
tag_image=soup.findAll("img") 
for image in tag_image: 
     print "Image: %(src)s" % image 
     urlretrieve(image["src"], "/home/mayank/Desktop/test") 

니펫입니까?

답변

1

//은 현재 프로토콜의 약식입니다. 속기를 사용하는 위키 백과 것 같다, 그래서 당신은 명시 적으로 대신 (파이썬은 어떤 이유로 가정한다) FTP의 HTTP 지정해야합니다 : @Blender

for image in tag_image: 
    src = 'http:' + image 
+0

감사 :이 난 것처럼 그러나 내 문제를 해결 한 가지를 추가하여 누구든지이 질문을 언급하면 ​​오도되지 않을 것입니다. http와 이미지를 첨부하면 답변에서 언급 한대로 작동합니다. 오히려 나는 이것을했다 : urlretrieve ('http :'+ image [ "src"], outpath) –

관련 문제