刚学爬虫对着视频想爬个网络小说但是代码写完不报错也不出结果,大佬们帮忙看看啥情况
import re import requests from lxml import etree headers = { "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" } proxy = { 'http': 'http://127.0.0.1:7890', 'https': 'http://127.0.0.1:7890' } # 定义小说首页 index_url = 'https://www.69shuba.pro/book/48273/' # 发送网络请求 response = requests.get(index_url, headers=headers) # 筛选链接和标题 info_list = re.findall('<li><a href ="(.*?)">(.*?)</a></li>', response.text) # 遍历列表,得到每章的部分链接和标题 for info in info_list: # 从元组中取出部分链接进行拼接,获取每章的页面链接 url = info[0] # 获取数据 response = requests.get(url, headers=headers) html_data = etree.HTML(response.text) # XPATH筛选出文本数据,并将数据列表转换成字符串 text_list = html_data.xpath('//html/body/div[2]/div[1]/div[3]/') text = ''.join(text_list) # 添加标题 book_text = '\n\n' + info[1] + '\n\n' print("正在下载" + info[1]) print(book_text) with open('阵问长生.txt', 'a', encoding='utf-8') as file: file.write(book_text)标签:info,python,text,list,爬虫,headers,book,报错,response From: https://blog.csdn.net/m0_45207459/article/details/139280187