爬取小说龙族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+"下载完成")
上一篇:复制构造函数 与 赋值函数 的区别


下一篇:运行现有网站的同时,配置FMS使用80端口代理rtmpt协议播放流媒体