'NoneType' object has no attribute 'text' in BeautifulSoup

前端 未结 3 1051
名媛妹妹
名媛妹妹 2021-01-13 03:07

I am trying to scrape Google results when I search \"What is 2+2\", but the following code is returning \'NoneType\' object has no attribute \'text\'.

3条回答
  •  醉话见心
    2021-01-13 03:25

    When you run the code, you might encounter an AttributeError:

    shell: AttributeError: 'NoneType' object has no attribute 'text'

    If that’s the case, then take a step back and inspect your previous results. Were there any items with a value of None? You might have noticed that the structure of the page is not entirely uniform. There could be an advertisement in there that displays in a different way than the normal job postings, which may return different results

    Reference:https://realpython.com/beautiful-soup-web-scraper-python/#extract-text-from-html-elements.

提交回复
热议问题