午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

瀏覽:184日期: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.leifengta.com.cn/wenda/Welcome to Python.org_files/modernizr.js.下載'></script><style type='text/css' adt='123'></style><link href='http://www.leifengta.com.cn/wenda/Welcome to Python.org_files/style.css' rel='stylesheet' type='text/css'><link href='http://www.leifengta.com.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.leifengta.com.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)文章:
主站蜘蛛池模板: 国产精品传媒在线观看 | 毛片的网址 | 99精品免费 | 欧美成人三级在线观看 | 欧美一区二区三区爽爽爽 | 丁香久久综合 | 看片在线| 亚洲美女一区二区三区 | 日本黄色免费网站 | 成人免费在线观看av | 国内精品久久久久久久 | 久草视频免费在线 | 午夜在线播放视频 | 免费黄网在线观看 | 午夜黄色av | 日韩一级黄色 | 成人免费播放视频 | 岛国精品在线 | 亚洲成人网在线播放 | 激情97| 免费观看黄色大片 | 天天干天天色天天爽 | 国产精品视频网址 | 综合色婷婷一区二区亚洲欧美国产 | 天天操天天爱天天干 | 99午夜视频 | 国产传媒免费在线观看 | 久久免费看片 | 91精品久久久久久 | 黄色一级网站 | 欧美一级性视频 | 国产在线专区 | 女人的天堂网 | 91精品久久久久久粉嫩 | 亚洲精品久久久久久久久 | 免费色网址 | 女18毛片 | 亚洲成人黄色网 | 婷婷视频在线 | 成人av在线看 | 日韩最新网址 |