**(爬取起点免费小说)
爬取的小说:爬取起点免费小说
代码:
import requests
from lxml import etree
headers = {
‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36’
}
response = requests.get(“https://book.qidian.com/info/1013432619”).text
html = etree.HTML(response)
link = html.xpath(’//ul[@class=“cf”]/li/a/@href’)
temp = []
for i in link:
start_url = “https:”
new_url = start_url + i
temp.append(new_url)

for a in temp:
response = requests.get(a, headers=headers).text
html = etree.HTML(response)
chapter_name = html.xpath(’//div[@class=“text-head”]/h3/text()’)
content = html.xpath(’//div[@class=“read-content j_readContent”]/p/text()’)
chapter_names = “”.join(chapter_name)
conn = “”.join(content).replace("\u3000", “”)
# print(chapter_name, conn)
with open(‘d:\m.txt’, ‘a’, encoding=“utf-8”)as f:
f.write(chapter_names)
f.write(’\n\n’)
f.write(conn)

结果:
爬取起点免费小说

相关文章:

  • 2021-11-04
  • 2021-11-23
  • 2021-04-05
  • 2021-12-05
  • 2021-11-26
  • 2021-07-13
  • 2021-06-10
猜你喜欢
  • 2021-07-08
  • 2021-11-21
  • 2021-06-25
  • 2022-01-01
  • 2021-12-05
  • 2022-12-23
  • 2021-12-05
相关资源
相似解决方案