我正在尝试使用正则表达式 python 从网页中获取代理 [英] im trying to get proxies using regex python out of a web page
本文介绍了我正在尝试使用正则表达式 python 从网页中获取代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import urllib.request
import re
page = urllib.request.urlopen("http://www.samair.ru/proxy/ip-address-01.htm").read()
re.findall('\d+\.\d+\.\d+\.\d+', page)
我不明白为什么它说:
文件C:\Python33\lib\re.py",第 201 行,在 findall 中返回 _compile(pattern, flags).findall(string)类型错误:不能在类似字节的对象上使用字符串模式
File "C:\Python33\lib\re.py", line 201, in findall return _compile(pattern, flags).findall(string) TypeError: can't use a string pattern on a bytes-like object
推荐答案
import urllib
import re
page = urllib.urlopen("http://www.samair.ru/proxy/ip-address-01.htm").read()
print re.findall('\d+\.\d+\.\d+\.\d+', page)
工作并给了我结果:
['056.249.66.50', '100.44.124.8', '103.31.250.115', ...
编辑
- 这适用于 python2.7
这篇关于我正在尝试使用正则表达式 python 从网页中获取代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文