酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

import requests from bs4 import beautifulsoup def get_poems(): url = "https://so.gushiwen.cn/gushi/tangshi.aspx" response = requests.get(url) response.encoding = "utf-8" soup = beautifulsoup(response.text, "html.parser") # 获取所有的诗列表 poem_list = soup.find_all("div", class_="typecont") poems = [] # 遍历诗列表,提取相关信息 for poem in poem_list: # 获取诗类型 poem_type = poem.find_previous_sibling("div", class_="bookml").find("span").text # 获取诗题目

poem_title = poem.find("b").text # 获取诗作者 poem_author = poem.find("p", class_="source").text.strip() # 获取诗内容 poem_content = poem.find("div", class_="contson").text.strip() # 创建诗对象,添加到诗列表中 poem_obj = { "type": poem_type, "title": poem_title, "author": poem_author, "content": poem_content } poems.append(poem_obj) return poems [2024-06-24 00:59:22 | AI写代码神器 | 316点数解答]

相关提问