Python Urllib.urlopen:IOError:[Errno socket错误] [Errno 10060]

时间:2017-08-23 05:08:48

标签: python sockets urllib

#!usr/bin/env python
# coding:utf-8

from socket import * 
import urllib2
import urllib
import re

def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html

def getImg(html):
    rule = r'src="(.*?\.jpg)" width'
    imgre = re.compile(rule)
    imglist = re.findall(imgre,html)
    i = 0
    for imgurl in imglist:
        i += 1
        urllib.urlretrieve(imgurl,'%d.jpg' %i)

html = getHtml("https://tieba.baidu.com/index.html")

print "downloading....................."
getImg(html)enter code here

当我运行代码时,可以获取 html imglist ,也会显示以下错误,现在我不知道该怎么做

  

追踪(最近一次通话):       File" C:/Users/18817/Desktop/getjpg.py" ;,第27行,在       GETIMG(HTML)       文件" C:/Users/18817/Desktop/getjpg.py" ;,第21行,在getImg中       urllib.urlretrieve(imgurl,' E:/getjpg/%s.jpg'%i)       文件" D:\ Python27 \ lib \ urllib.py",第98行,在urlretrieve中       return opener.retrieve(url,filename,reporthook,data)       文件" D:\ Python27 \ lib \ urllib.py",第245行,在检索中       fp = self.open(url,data)       文件" D:\ Python27 \ lib \ urllib.py",第213行,处于打开状态       return getattr(self,name)(url)       文件" D:\ Python27 \ lib \ urllib.py",第457行,在open_https中       return self.http_error(url,fp,errcode,errmsg,headers)       文件" D:\ Python27 \ lib \ urllib.py",第377行,在http_error中       result =方法(url,fp,errcode,errmsg,headers)       文件" D:\ Python27 \ lib \ urllib.py",第642行,http_error_302       标题,数据)       文件" D:\ Python27 \ lib \ urllib.py",第669行,在redirect_internal中       return self.open(newurl)       文件" D:\ Python27 \ lib \ urllib.py",第213行,处于打开状态       return getattr(self,name)(url)       文件" D:\ Python27 \ lib \ urllib.py",第350行,在open_http中       h.endheaders(数据)       文件" D:\ Python27 \ lib \ httplib.py",第1038行,在endheaders中       self._send_output(MESSAGE_BODY)       文件" D:\ Python27 \ lib \ httplib.py",第882行,在_send_output中       self.send(MSG)       文件" D:\ Python27 \ lib \ httplib.py",第844行,发送       self.connect()       文件" D:\ Python27 \ lib \ httplib.py",第821行,在连接中       self.timeout,self.source_address)       文件" D:\ Python27 \ lib \ socket.py",第575行,在create_connection中       提出错误        IOError:[Errno套接字错误] [Errno 10060]

0 个答案:

没有答案