當前位置:首頁 » 編程語言 » 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 18:41:52 瀏覽:62
SQL指定的服務並未以 發布:2025-02-05 18:40:09 瀏覽:972
電腦連接不了伺服器什麼意思 發布:2025-02-05 18:34:46 瀏覽:355
2015版dw怎麼配置站點 發布:2025-02-05 18:33:37 瀏覽:429
php數組中重復值 發布:2025-02-05 18:16:59 瀏覽:365
分布式存儲優點 發布:2025-02-05 18:15:29 瀏覽:644
徵婚交友源碼 發布:2025-02-05 17:45:24 瀏覽:918
3nvm伺服器怎麼搭建 發布:2025-02-05 17:43:52 瀏覽:661
cocosandroid開發 發布:2025-02-05 17:22:17 瀏覽:669
編程員發型 發布:2025-02-05 17:09:18 瀏覽:226