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

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

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

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

問題描述

大神們:

我想把htm文件中的第一個<link到第二個<link之間的所有內(nèi)容另存為一個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'>

提取的內(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.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 編程
相關(guān)文章:
主站蜘蛛池模板: 午夜视频偷拍在线观看免费 | 中文字幕日韩欧美一区二区三区 | 国产视频二区 | 亚洲欧美日韩在线2020 | 亚洲精品亚洲人成在线麻豆 | 女人被狂躁的免费视频网站软件 | 中文精品久久久久国产网址 | 欧美日韩亚洲国内综合网俺 | 欲色影视天天一区二区三区色香欲 | 香港三级理论在线影院 | 鲁大师视频在线www观看 | 国产成人宗合 | 国产一区二区三区四区小蝌蚪 | 久久久久综合中文字幕 | 亚洲国产精品一区二区不卡 | 成人合成mv福利视频网站 | 久久综合久久久久 | 一区二区三区四区亚洲 | 黄色网址www | 国产精品夫妇久久 | 一级成人生活片免费看 | 婷婷99精品国产97久久综合 | 国产成人精品18 | 黄色大片国产 | 啪啪中文字幕 | 国产一级爱片在线播放 | 免费的黄视频 | 午夜色a大片在线观看免费 午夜色图 | 久久天天躁狠狠躁夜夜中文字幕 | 日本免费毛片在线高清看 | 国产福利视频精品 | 青青草在线免费观看 | aaa级精品久久久国产片 | 日本黄大片在线观看视频 | 国产免费不卡v片在线观看 国产免费不卡视频 | 免费一级国产大片 | 久久精品最新免费国产成人 | 国产综合视频在线 | 一区二区三区www | 自拍网在线 | 国产高清不卡视频在线播放 |