html = getHtml("http://image.baidu.com/channel/star")
print getImg(html)
urllist=getImg(html)
x=0
for imgurl in urllist:
urllib.urlretrieve(imgurl,'%s.jpg' % x)
time.sleep(10)
x+=1
然后报错了:
Traceback (most recent call last):
File "D:\BaiduYunDownload\Python\web crawler.py", line 24, in <module>
urllib.urlretrieve(imgurl,'%s.jpg' % x)
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 326, in open_http
if not host: raise IOError, ('http error', 'no host given')
IOError: [Errno http error] no host given