From 95bb69bb004938bc06ba9a6adea1130b7f6076cc Mon Sep 17 00:00:00 2001 From: pmc3for6p <1419578769@qq.com> Date: Thu, 13 Jun 2024 22:32:14 +0800 Subject: [PATCH] ADD file via upload --- 2.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 2.py diff --git a/2.py b/2.py new file mode 100644 index 0000000..c716c32 --- /dev/null +++ b/2.py @@ -0,0 +1,29 @@ +import csv + +import requests +from bs4 import BeautifulSoup + +url = 'https://88xiaoshuo.net/type/' +h = { + 'User-Agent': + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0' +} +response = requests.get(url) +content = response.content.decode("utf8") +soup = BeautifulSoup(content, 'html.parser') +a = soup.select('ul.list > li') +list = [] +for i in a : + soup1 = BeautifulSoup(str(i), 'html.parser') + title = soup1.select('p > a')[0].text + author = soup1.select('p > a')[1].text + leixing = soup1.select('p > span')[0].text + cpntext = soup1.select('p ')[2].text + list.append([title,author,leixing,cpntext]) + +for i in list: + print(i) +with open("xs.csv",'w',encoding="utf8") as f: + writer = csv.writer(f) + writer.writerow(['书名','作者','类型','内容']) + writer.writerows(list) \ No newline at end of file