标签:agent 代码实现 实践 电话号码 生活 epo 规律 windows text
re简单实践
分析网页,很容易得出规律:
css字体颜色标记电话号码
代码实现:
import re import requests headers = { "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0" } reponse = requests.get("http://changyongdianhuahaoma.51240.com/",headers=headers).text pat1 = re.compile(r‘<tr bgcolor="#EFF7F0">[\s\S]*?<td>(.*?)</td>[\s\S]*?<td>[\s\S]*?</td>[\s\S]*?</tr>‘) pat2 = re.compile(r‘<tr bgcolor="#EFF7F0">[\s\S]*?<td>[\s\S]*?</td>[\s\S]*?<td>(.*?)</td>[\s\S]*?</tr>‘) data1 = pat1.findall(reponse) data2 = pat2.findall(reponse) print(data1) print(data2) resultlist = [] for i in range(0, len(data1)): resultlist.append(data1[i]+data2[i]) print(resultlist)
最后效果:
标签:agent 代码实现 实践 电话号码 生活 epo 规律 windows text
原文地址:https://www.cnblogs.com/liuchaodada/p/12168999.html