数据分析训练营-第五周-百度针对xpath反爬策略解决
程序员文章站
2022-03-08 08:01:37
xpath无法识别出被注释的代码,所以可以用re模块正则表达式解决import rewith open('meiju1.html','r',encoding='utf-8') as f: html = re.sub('\n','',f.read()) title_pattern = '
.*?(.*?)'#()表示提取内容 t...
xpath无法识别出被注释的代码,所以可以用re模块正则表达式解决
import re
with open('meiju1.html','r',encoding='utf-8') as f:
html = re.sub('\n','',f.read())
title_pattern = '<div class="threadlist_title pull_left j_th_tit ">.*?<a.*?>(.*?)</a>'#()表示提取内容
title_s = re.findall(title_pattern,html)
for title in title_s:
print(title)
本文地址:https://blog.csdn.net/lildn/article/details/110892414
上一篇: Python编程:找出3~6位自幂数
下一篇: QT小项目Demo【有功能图】