|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
强迫关闭时什么意思?
import urllib.request
import re
def open_url(url):
req = urllib.request.Request(url)
req.add_header('User-Agent','Mozilla/5.0(Macintosh;Intel Mac OS X 10_10_1)) AppleWebKit/537.36(KHTML,like Gecko) Chrome/39.0.2171.95 Safari/537.36')
page = urllib.request.urlopen(req)
html = page.read().decode('utf-8')
return html
def get_img(html):
p = r'(?:(?:[0,1]?\d?\d|2[0-4]\d|25[0-5])\.){3}(?: [0,1]?\d?\d|2[0-4]\d|25[0-5])'
iplist = re.findall(p,html)
for each in iplist:
print(each)
if __name__ == '__main__':
url = "http://cn-proxy.com"
get_img(open_url(url))
运行结果:
Traceback (most recent call last):
File "C:\Users\dell\Desktop\666 - 副本.py", line 24, in <module>
get_img(open_url(url))
File "C:\Users\dell\Desktop\666 - 副本.py", line 7, in open_url
page = urllib.request.urlopen(req)
File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 544, in _open
'_open', req)
File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1346, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1321, in do_open
r = h.getresponse()
File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1331, in getresponse
response.begin()
File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 297, in begin
version, status, reason = self._read_status()
File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
|
|