STEP #1

(1/2)

此处切换ai服务商,可对比多家ai的回复,取最优解。

上一步下一步关闭
酷代码 AI
菜单
全部AI  /  热门  /  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点数解答]

相关提问