大佬帮帮看看为什么错 谢谢

import requests
from bs4 import BeautifulSoup
#网页html代码
if name == “main”:
headers ={“User-Agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36”}
URL = “https://www.ddxstxt8.com/10_10364/”
html = requests.get(url=URL,headers=headers).text
soup = BeautifulSoup(html,‘lxml’)
dd_list = soup.find_all(‘div’,id=‘list’)
fp = open(’./yijian.txt’,‘w’,encoding=‘utf-8’)
for dd in dd_list:
title = dd.a.string
detail_url = ‘https://www.ddxstxt8.com/10_10364/’ + dd.a[‘href’]
detail_page_text = requests.get(url=detail_url,headers=headers).text
detail_soup = BeautifulSoup(detail_page_text,‘lxml’)
div_tag = detail_soup.find(‘div’,id_=‘content’)
content = div_tag.text
fp.write(title + ‘:’ + content + ‘\n’)
print(title,‘爬取成功!!!’)

帮帮看看错在哪。
报错原因:
Traceback (most recent call last):
File “D:/pycharm/daima/umtitled/爬虫/小说爬取/笔趣阁小说爬取.py”, line 17, in
content = div_tag.text
AttributeError: ‘NoneType’ object has no attribute ‘text’

上一篇:爬取三国演义的章节和内容


下一篇:采用 this 关键字是为了解决实例变量(private String name)和局部变量(setName(String name)中的name变量)之间发生的同名的冲突。