抓取最后的“下一页”后,BeautifulSoup AttributeError

它遍历所有20个“下一页”,但最后没有命中“ else”语句以表示不再有页面,并引发以下内容:

第38行(if语句所在的位置)上的“ AttributeError:'NoneType'对象没有属性'get'”。

while True:
response = requests.get(url)
data = response.text
soup = BeautifulSoup(data,'html.parser')
blabbermouth_articles = soup.find_all('article',{'class': 'category-news'})
# print(response)

for blabbermouth_article in blabbermouth_articles:
    image = blabbermouth_article.find('img').get('src')
    title = blabbermouth_article.find('a').get('title')
    shortLink = blabbermouth_article.find('a').get('href')
    print(title)
    link = "https://www.blabbermouth.net" + shortLink
    print(link)
    print(image)

    article_no += 1
    all_blabbermouth_articles[article_no] = [image,title,link]

next_page_tag = soup.find('a',{'class': 'next_page'})
if next_page_tag.get('href'):
    url = 'https://www.blabbermouth.net' + next_page_tag.get('href')
    print(url)
else:
    print("END OF LAST PAGE")
    break
wkz123456 回答:抓取最后的“下一页”后,BeautifulSoup AttributeError

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3163388.html

大家都在问