如何在python中使用正则表达式解析所有IP地址的网页?
这是我管理得最多的一次:如何在python中使用正则表达式解析所有IP地址的网页?,python,regex,proxy,urllib2,urllib,Python,Regex,Proxy,Urllib2,Urllib,这是我管理得最多的一次: import urllib.request page = urllib.request.urlopen("http://www.samair.ru/proxy/ip-address-01.htm") page('\d+\.\d+\.\d+\.\d+') 您使用的是什么版本的回溯(最近一次调用):文件“C:\Users\Teli\Desktop\1.py”,第4行,在re.findall('\d+\.\d+\.\d+\.\d+',第页)文件“C:\Python33\
import urllib.request
page = urllib.request.urlopen("http://www.samair.ru/proxy/ip-address-01.htm")
page('\d+\.\d+\.\d+\.\d+')
您使用的是什么版本的回溯(最近一次调用):文件“C:\Users\Teli\Desktop\1.py”,第4行,在re.findall('\d+\.\d+\.\d+\.\d+',第页)文件“C:\Python33\lib\re.py”,第201行,在findall return\u compile(pattern,flags)中。findall(string)TypeError:无法在字节上使用字符串模式,如objecti使用的是2.7。你在用3.x吗?chown我不知道你在用什么版本的python
In [1]: import urllib2
In [2]: import re
In [3]: page = urllib2.urlopen("http://www.samair.ru/proxy/ip-address-01.htm").read()
In [4]: re.findall('\d+\.\d+\.\d+\.\d+', page)
Out[4]:
['101.226.74.168',
'101.255.60.162',
'101.50.17.123',
'103.247.16.2',
'103.247.16.97',
'103.28.227.78',
'103.7.248.161',
'106.120.98.166',
'107.16.66.225',
'108.166.87.24',
'109.123.111.99',
'109.127.37.117',
'109.175.8.45',
'109.175.8.53',
'109.207.61.160',
'109.207.61.172',
'109.207.61.173',
'109.207.61.194',
'109.207.61.210',
'109.230.66.7']