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

您的位置:首頁技術文章
文章詳情頁

python處理文件內容的正確姿勢該怎樣?

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

問題描述

大神們:

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

提取的內容應該是:

<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)

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 九九免费精品视频在这里 | 国产一级二级三级毛片 | 韩国女主播青草在线观看 | 午夜寂寞福利 | 国内精品视频成人一区二区 | 亚洲欧美久久 | 欧美野外性k8播放性迷宫 | 欧美大片一区 | 日本三级网站在线线观看 | 特黄特a级特别特级特毛片 特黄特黄 | 日本三本道 | 中文字幕一区二区三区精品 | 国产午夜毛片v一区二区三区 | 久久精品国产免费中文 | 久久99毛片免费观看不卡 | 国产精品二区高清在线 | 最近中文字幕精彩视频 | 男人的天堂欧美 | 成人免费高清视频网址 | 亚洲视频中文字幕在线 | 深夜福利国产福利视频 | 一级毛片q片 | 欧美一区二区不卡视频 | 99精品这里只有精品高清视频 | 国产99精品免费视频看6 | 久在草视频 | 欧美成人精品动漫在线专区 | 久久精品欧美日韩精品 | 2021国产精品系列一区二区 | 欧美一级情欲片在线 | 免费一级毛片女人图片 | 黑人一级黄色片 | 步兵社区在线观看 | 国产精品久久久久久久久久影院 | 天天五月天丁香婷婷深爱综合 | 特级淫片日本高清视频 | 午夜大片免费男女爽爽影院久久 | 欧美精品片在线观看网站 | 国产高清美女一级a毛片久久w | 日韩美女免费线视频 | 一级国产视频 |