当前位置:首页 » 编程语言 » python正则提取html

python正则提取html

发布时间: 2023-08-17 05:55:11

❶ 在python中,利用正则表达式在html中,提取每三行中的特定字符,形成一个列表,每个列表中的元

import re

file_object = open('temp.txt')
try:
str = file_object.read( )
finally:
file_object.close( )
result = re.findall("(\d+%) S\s+\d+ (\d+)K\s+(\d+)K",str)
f = open("test.csv","w")
for line in result:
f.write("%s,%s,%s\n"%(line[0],line[1],line[2]))
f.close()

❷ python怎样使用正则表达式获得html标签数据

正则的话
import re
html = "<a href='xxx.xxx' title='xxx.xxx.xxx'>sample text1</a>abcdef<a href='xxx.xxx' title='xxx.xxx.xxx'>sample text2</a>"
result = map(lambda name: re.sub("<a href=.*?>","",name.strip().replace("</a>","")), re.findall("<a href=.*?>.*?</a>",html))
print result
上面代码会把所有a tag里的东西存在result这个list里面。另外python有个模块叫Beautiful Soup,专门用来处理html的,你有空可以看下

❸ 用python中re正则化处理HTML

用replace函数,先把<style>。。。</style>等不需要的的内容替换为空
再使用正则提取。
或者使用正则,只提取
<p>...</p>之间的内容

❹ Python怎样抓取当前页面HTML内容

Python用做数据处理还是相当不错的,如果你想要做爬虫,Python是很好的选择,它有很多已经写好的类包,只要调用,即可完成很多复杂的功能,此文中所有的功能都是基于BeautifulSoup这个包。
1 Pyhton获取网页的内容(也就是源代码)
page = urllib2.urlopen(url)
contents = page.read()
#获得了整个网页的内容也就是源代码 print(contents)
url代表网址,contents代表网址所对应的源代码,urllib2是需要用到的包,以上三句代码就能获得网页的整个源代码
2 获取网页中想要的内容(先要获得网页源代码,再分析网页源代码,找所对应的标签,然后提取出标签中的内容)

❺ python语言,怎么用正则表达式提取HTML标签<h3

importre
text='''<br>
<h3align="center"class="STYLE3">姓名:张三</h3>
<h3align="center"class="STYLE3">2013/6/9</h3>'''
htm=re.findall(r"<h3.*?>.*?</h3>",text)
fortinhtm:
k=re.sub("<h3.*?>","",t)
k=re.sub("</h3>","",k)
print(k.replace("姓名:",""))

❻ python如何一个正则表达式获取html中表格内容

varreg=/<table>(?:(?!</table>)[sS])*</table>/gi;

热点内容
支持ftp的免费空间 发布:2025-02-05 16:32:00 浏览:886
python时间比较 发布:2025-02-05 16:31:46 浏览:48
手机银行的密码怎么改密码忘了怎么办啊 发布:2025-02-05 16:02:02 浏览:178
算法牛人左 发布:2025-02-05 15:31:02 浏览:438
php筛选功能 发布:2025-02-05 15:29:09 浏览:167
ip匹配服务器 发布:2025-02-05 15:10:35 浏览:909
php语法后 发布:2025-02-05 15:10:34 浏览:59
oppor9s怎么压缩文件 发布:2025-02-05 15:00:34 浏览:639
苹果耳塞怎么改安卓也能用 发布:2025-02-05 14:50:54 浏览:558
安卓如何鉴别手机真假 发布:2025-02-05 14:28:15 浏览:121