爬取小说龙族5
作者:互联网
"""
姓名 :赵康乐
职业 :学生
任务 :爬取小说龙族5并保存
日期 :2022-2-3
"""
import requests
from bs4 import BeautifulSoup
url = "https://www.75xs.cc/book/longzuV/"
headers = {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0"
}
response = requests.get(url=url, headers=headers).text.encode("iso-8859-1")
# print(response)
soup = BeautifulSoup(response, "lxml")
list = soup.find("div", class_="m-book-list")
# print(list)
lis = list.find_all("li", class_="line3")
for li in lis:
title = li.a.text
new_url = "https://www.75xs.cc" + li.a["href"]
resp = requests.get(new_url,headers=headers).text.encode("iso-8859-1")
new_soup = BeautifulSoup(resp,"lxml")
con = new_soup.find("div",class_="content")
content = con.text
with open("D:\桌面\龙族5.txt",mode="a",encoding="utf-8") as fp:
fp.write(title)
fp.write(content)
print(title+"下载完成")
标签:龙族,soup,url,list,li,爬取,headers,new,小说 来源: https://www.cnblogs.com/zhaokangle/p/15861816.html