免责声明:本文仅做分享...
dp自动化
from DrissionPage import ChromiumPage
import csv
url = "https://www.yinhuadm.vip/"
page = ChromiumPage()
page.get(url)
# 找到搜索按钮
search_btn = page.ele(".search-input")
search_content = input("请输入搜索内容:")
search_btn.input(search_content)
# 点击搜索按钮
search_go = page.ele(".search-btn search-go")
search_go.click()
# 获取所有相关的搜索结果
result_list = page.eles(".module-card-item module-item")
# print(len(result_list))
# 保存数据到csv文件
with open(f"樱花动漫--{search_content}.csv", "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerow(["标题", "详情链接", "相关内容"])
for i, result in enumerate(result_list):
# 获取标题
title = result.ele('x://div[@class="module-card-item-title"]/a/strong').text
# 获取详情链接
detail_link = result.ele('x://div[@class="module-card-item-title"]/a').attr(
"href"
)
# 获取相关内容
content1 = result.ele('x://div[@class="module-info-item-content"]').text
# content2 = result.ele('x://div[@class="module-info-item-content"]').text
writer.writerow([title, detail_link, content1])
print(f"保存成功--{search_content}.csv")