|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import re
- import os
- import urllib.request
- from urllib.error import HTTPError, URLError
- def open_url(url):
- req = urllib.request.Request(url)
- req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36')
- try:
- response = urllib.request.urlopen(req)
- except (HTTPError, URLError) as e:
- print(e)
- try:
- html = response.read().decode('utf-8')
- except UnboundLocalError as e:
- print(e)
- return html
- def save_file(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])'
- ip_list = re.findall(p, html)
- for each in ip_list:
- print(eachh)
- if __name__ == "__main__":
- url = "https://cn.proxy.com"
- save_file(open_url(url))
复制代码
这几个异常如何解决? |
|