|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import re
url = 'http://www.xicidaili.com/nn'
req = urllib.request.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'
)
response = urllib.request.urlopen(req)
html = response.read().decode('utf-8')
result = re.findall(r'(((2[0-4]\d|25[0-5]|[0,1]{0,1}\d{0,1}\d)\.){3}(2[0-4]\d|25[0-5]|[0,1]{0,1}\d{0,1}\d))',html)
print(html)
print(result)
代码如上,爬取后得到的结果如图。
IP地址是得到了,但是它后面跟一串奇怪的数字。是我的正则表达式错了吗?
先谢谢了。 |
|