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

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

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

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

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

<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://m.4tl426be.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)文章:
主站蜘蛛池模板: 香蕉大人久久国产成人av | www.久久99 | 亚洲一区二区 | 亚洲精品久久久久久一区二区 | 亚洲人成人一区二区在线观看 | 日韩免费看片 | 久久精品亚洲 | 狠狠操天天操 | 国产精品视频区 | 久久久www | 久久久国产精品 | 日韩欧美一区在线 | 黄色在线免费观看 | 欧美日韩高清 | 日中文字幕在线 | 九九热在线免费视频 | 久久91 | 日本午夜一区二区三区 | 久久99精品久久久久久 | 国产精品高潮呻吟久久久久 | 国产精品一区二区无线 | 97在线超碰 | 综合欧美亚洲 | 国产精品一区视频 | 精品国偷自产在线 | 国产精品一区二区电影 | 三级视频在线观看电影 | 日韩中文字幕视频 | 国产欧美久久一区二区三区 | 久久99成人 | 四色成人av永久网址 | 日韩一级一区 | 日韩精品一二三 | 成人午夜视频在线观看 | 日本激情视频中文字幕 | av看片网| 国产成人精品网站 | 99精品国产一区二区三区 | 亚洲精品国产成人 | 99视频在线免费观看 | 韩国欧洲一级毛片 |