酷代码 AI
菜单
服务商

import requests from bs4 import beautifulsoup import pandas as pd url = "https://so.gushiwen.cn/gushi/tangshi.aspx" response = requests.get(url) soup = beautifulsoup(response.text, 'html.parser') # 提取所需数据 poems_data = [] for row in soup.find_all('tr', class_='tlist')[1:]: cols = row.find_all('td') type_ = cols.text.strip() title = cols.a.text.strip() content = cols.text.replace('\n', '').replace('\t', '') author = cols.text.strip() poems_data.append([type_, title, conte

nt, author]) # 创建DataFrame对象 df = pd.DataFrame(poems_data, columns=['Type', 'Title', 'Content', 'Author']) # 将DataFrame数据写入CSV文件 df.to_csv('poems.csv', index=False) [2024-06-24 02:04:56 | AI写代码神器 | 120点数解答]

相关提问
发财导航,免费问AI
实用工具查看更多
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]
数独游戏 [娱乐类]
经典推箱子 [娱乐类]
AI摸鱼五子棋 [娱乐类]