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

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

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

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

問(wèn)題描述

大神們:

我想把htm文件中的第一個(gè)<link到第二個(gè)<link之間的所有內(nèi)容另存為一個(gè)htm該怎么寫比較簡(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.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

問(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)文章:
主站蜘蛛池模板: 男女免费观看视频 | 99re热久久| 亚州男人天堂 | 三上悠亚免费一区二区在线 | 久久18| 97在线视频观看 | 欧美 日韩 国产 在线 | 成人a毛片手机免费播放 | 免费一级毛片在线播放放视频 | 视频偷拍一级视频在线观看 | 亚洲精品久久久久影院 | 亚洲国产精品一区二区久 | 在线观看亚洲免费 | www中文字幕在线观看 | 手机在线看福利 | 成人夜色视频网站在线观看 | 国产精品亚洲欧美日韩久久 | 亚洲精品国产第一区第二区国 | 孕妇交 | 68久久久久欧美精品观看 | 成人爽a毛片在线视频网站 成人爽爽大片在线观看 | 国产精品自在线天天看片 | 奇米影视7777久久精品 | 日本不卡在线一区二区三区视频 | 波多野结衣在线免费视频 | 久久精品国产精品亚洲 | 中文字幕最新中文字幕中文字幕 | 亚洲国产成人精品一区二区三区 | 国产色a在线观看 | 国产黄色一级网站 | 欧美一级黄视频 | 久久久久久在线 | 国产黄色a三级三级三级 | 亚洲性影院 | 欧美黑大粗硬毛片视频 | 在线欧美精品二区三区 | 免费黄色网址在线播放 | 亚洲欧美一区二区三区在线播放 | 欧美日韩高清在线观看一区二区 | 欧美a欧美| 国产精品国产三级国产an |