酷代码 AI
菜单
服务商

Python代码实现:采集唐诗三百首内容并保存为txt文件

```python poem_response = requests.get(poem_url) poem_content = re.findall(r'<div class="contson" id="contson.*?>(.*?)</div>', poem_response.text, re.s)[0] poems.append((info[1], info[2], poem_content)) return poems # 爬取唐诗三百首 url = "https://so.gushiwen.cn/gushi/tangshi.aspx" poems = fetch_poems(url) # 保存到txt文件 with open("唐诗三百首.txt", "w", encoding="utf-8") as f: for poem in poems: f.write(f"{poem[0]} {poem[1]} {poem[2]} ") ``` ######[AI写代码神器 | 208点数解答 | 2024-06-23 11:07:39]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]