av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python處理文件內(nèi)容的正確姿勢(shì)該怎樣?

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

問(wèn)題描述

大神們:

我想把htm文件中的第一個(gè)<link到第二個(gè)<link之間的所有內(nèi)容另存為一個(gè)htm該怎么寫(xiě)比較簡(jiǎn)潔。

<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.4tl426be.cn/wenda/Welcome to Python.org_files/modernizr.js.下載'></script><style type='text/css' adt='123'></style><link href='http://www.4tl426be.cn/wenda/Welcome to Python.org_files/style.css' rel='stylesheet' type='text/css'><link href='http://www.4tl426be.cn/wenda/Welcome to Python.org_files/mq.css' rel='stylesheet' type='text/css' media='not print, braille, embossed, speech, tty'>

提取的內(nèi)容應(yīng)該是:

<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.4tl426be.cn/wenda/Welcome to Python.org_files/modernizr.js.下載'></script><style type='text/css' adt='123'></style><link

問(wèn)題解答

回答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)

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 亚洲女人毛茸茸 | 婷婷久久五月 | 免费一级片 | 亚洲专区在线 | 青青草精品| 欧美另类z0zx974 | 欧美视频一区二区 | 毛片www| 黄色片免费网站 | 精品在线播放 | 五月综合色 | 国产二三区| 国产一级在线 | 中文字幕亚洲精品 | 日韩av在线网站 | 四虎成人影视 | 久久久久久久97 | 成人h视频在线观看 | 黄色一级录像 | 青青草在线观看视频 | 在线观看成人免费视频 | 久久久久久久网 | 日韩中文视频 | 天天干夜夜艹 | 91精品国产日韩91久久久久久 | 超碰在线成人 | 国产又黄又爽视频 | 国产精品久久久久久久午夜 | 日韩一区二区三区在线播放 | 国产精品久久久久久久午夜 | 夜夜肉她怀孕h周君彦 | 国产一级视频在线观看 | 天天干在线观看 | av在线天堂 | 欧美日韩黄 | 日本成人中文字幕 | 九色在线视频 | 亚洲欧美日韩国产精品 | 九九久久久 | 日韩免费在线视频 | 亚洲一区在线播放 |