You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
914 B

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)