亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

python處理文件內容的正確姿勢該怎樣?

瀏覽:84日期:2022-08-23 11:36:53

問題描述

大神們:

我想把htm文件中的第一個<link到第二個<link之間的所有內容另存為一個htm該怎么寫比較簡潔。

<meta http-equiv='X-UA-Compatible' content='IE=edge'><link rel='prefetch' ><meta name='application-name' content='Python.org'><meta name='msapplication-tooltip' content='The official home of the Python Programming Language'><meta name='apple-mobile-web-app-title' content='Python.org'><meta name='apple-mobile-web-app-capable' content='yes'><meta name='apple-mobile-web-app-status-bar-style' content='black'><meta name='viewport' content='width=device-width, initial-scale=1.0'><meta name='HandheldFriendly' content='True'><meta name='format-detection' content='telephone=no'><meta http-equiv='cleartype' content='on'><meta http-equiv='imagetoolbar' content='false'><script type='text/javascript' async='' src='https://ssl.google-analytics.com/ga.js'></script><script src='http://www.aoyou183.cn/wenda/Welcome to Python.org_files/modernizr.js.下載'></script><style type='text/css' adt='123'></style><link href='http://www.aoyou183.cn/wenda/Welcome to Python.org_files/style.css' rel='stylesheet' type='text/css'><link href='http://www.aoyou183.cn/wenda/Welcome to Python.org_files/mq.css' rel='stylesheet' type='text/css' media='not print, braille, embossed, speech, tty'>

提取的內容應該是:

<link rel='prefetch' ><meta name='application-name' content='Python.org'><meta name='msapplication-tooltip' content='The official home of the Python Programming Language'><meta name='apple-mobile-web-app-title' content='Python.org'><meta name='apple-mobile-web-app-capable' content='yes'><meta name='apple-mobile-web-app-status-bar-style' content='black'><meta name='viewport' content='width=device-width, initial-scale=1.0'><meta name='HandheldFriendly' content='True'><meta name='format-detection' content='telephone=no'><meta http-equiv='cleartype' content='on'><meta http-equiv='imagetoolbar' content='false'><script type='text/javascript' async='' src='https://ssl.google-analytics.com/ga.js'></script><script src='http://www.aoyou183.cn/wenda/Welcome to Python.org_files/modernizr.js.下載'></script><style type='text/css' adt='123'></style><link

問題解答

回答1:

import retext = ''with open('read.html', 'r') as rf: text = rf.read() pattern = r'<link[sS]*?<link'results = re.findall(pattern, text)if results: r = results[0] with open('write.html', 'w') as wf:wf.write(r) ================================================with open('read.html', 'r') as rf: with open('write.html', 'w') as wf:num = 0for line in rf.readlines(): if line.startswith('<link'):num += 1continue if num == 2:break wf.writelines(line)

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 国产日韩精品一区二区在线观看 | 在线免费看网站 | 亚洲国产成人久久三区 | 本道久久| 95香蕉视频| 欧美大jj| 国产精品日韩一区二区三区 | 亚洲天堂精品视频 | 99re6热视频精品免费观看 | 免费无毒片在线观看 | 人人做天天爱夜夜爽中字 | 精品一区二区久久久久久久网精 | 欧美亚洲国产另类 | 国产日韩一区二区三区 | 日本免费久久久久久久网站 | 快猫在线观看入口免费网站满十八 | 亚洲精品成人7777在线观看 | 91精品国产综合久久久久久 | 年轻人www影视 | 国产精品揄拍一区二区 | 三级中文字幕永久在线视频 | 国产成人精品免费久久久久 | 91爱啪啪 | 亚洲午夜日韩高清一区 | 九色国产在视频线精品视频 | 欧美一区二区三区久久综合 | 欧美干色 | 麻豆传媒官网入口 | 日韩国产有码在线观看视频 | 成人在线观看网址 | 亚洲+自拍+色综合图区一 | 日韩精品大片 | 中文字幕欧美一区 | 青青青国产色视频在线观看 | 色九九亚洲偷偷动态图 | 国产111111在线观看 | 亚洲国产精品线在线观看 | 偷窥自拍有声 | 欧美成人四级剧情在线播放 | 亚洲香蕉毛片久久网站老妇人 | 婷婷播放器 |