国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

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

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

問題描述

大神們:

我想把htm文件中的第一個(gè)<link到第二個(gè)<link之間的所有內(nèi)容另存為一個(gè)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.cgvv.com.cn/wenda/Welcome to Python.org_files/modernizr.js.下載'></script><style type='text/css' adt='123'></style><link href='http://www.cgvv.com.cn/wenda/Welcome to Python.org_files/style.css' rel='stylesheet' type='text/css'><link href='http://www.cgvv.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.cgvv.com.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)

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 国产精品理论 | 中文字幕无线精品乱码一区 | 欧美一级艳片视频免费观看 | 国产一区二区三区免费看 | 亚洲综合一区二区三区 | 国产精品人成人免费国产 | 男人都懂的网址在线看片 | a三级黄色片 | 成人黄色毛片 | 亚洲综合图片人成综合网 | 日本色哟哟 | 毛片免费大全 | 日本免费一级 | 亚洲国产精品一区二区九九 | 99re5久久在热线播放 | 亚洲综合久久久久久中文字幕 | 亚洲国产精品久久久久久网站 | 国产精品久久福利网站 | 美女又黄又免费的视频 | 久久免费看| 成年免费观看 | 黄人成a动漫片免费网站 | 欧美黄a | 美国一级毛片片免费 | 欧美一级片免费看 | 亚洲美女视频一区二区三区 | aaa级毛片 | 亚洲天堂伊人 | 免费区欧美一级毛片 | 亚洲精品一区二区三区不卡 | 99er精品| 久久久久久亚洲精品 | 亚洲国产精品线观看不卡 | 日本卡一卡2卡3卡4精品卡无人区 | 老外黑人欧美一级毛片 | 久久网站免费观看 | 99成人国产精品视频 | 一级一级一片在线观看 | 国产系列在线播放 | 国产手机在线精品 | 97免费公开视频 |