import re #导入正则
a = "\d+.\d+.\d+.\d+" #设置匹配ip地址规则
b = re.compile(a) #编译
c = b.findall(ip) #匹配
print c
以下是爬虫部分:
req = urllib2.urlopen("http://192.168.1.1:8080/?action=stream")
buf = req.read(71) #数据头图片长度
本文介绍了一种使用Python正则表达式进行IP地址匹配的方法,并展示了如何利用urllib2库从指定URL获取网络流数据。通过编译正则表达式并应用findall方法来查找所有匹配的IP地址。
import re #导入正则
a = "\d+.\d+.\d+.\d+" #设置匹配ip地址规则
b = re.compile(a) #编译
c = b.findall(ip) #匹配
print c
以下是爬虫部分:
req = urllib2.urlopen("http://192.168.1.1:8080/?action=stream")
buf = req.read(71) #数据头图片长度
5305

被折叠的 条评论
为什么被折叠?