1

I want to scrape data from inner links, when I use this code give me ('NoneType' object has no attribute 'text')

#Scrappin data from inner links
#Scrappin salaries
for link in links:
    result = requests.get(link)
    src = result.content
    soup = BeautifulSoup(src, "lxml")
    salaries = soup.find("span" ,{"class":"css-4xky9y"})
    salary.append(salaries.text)

give me Error

AttributeError                            Traceback (most recent call last)
<ipython-input-34-43f9a3ba50f1> in <module>
      8     salaries = soup.find("span" ,{"class":"css-4xky9y"})
      9     #print(salaries.text.strip())
---> 10     salary.append(salaries.text.strip())

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

but when I scrape off another span in the same page, don't give me an Error

for link in links:
    result = requests.get(link)
    src = result.content
    soup = BeautifulSoup(src, "lxml")
    experienc= soup.find("span" ,{"class":"css-wn0avc"})
    print(experienc.text)
    salary.append(experienc.text)

output: Experience Needed: Experience Needed: Experience Needed: Experience Needed: Experience Needed: Experience Needed: Experience Needed:

  • 1
    What that means, of course, is that `soup.find` did not find anything. Have you done `print(src)` to make sure it looks like you think it does? You didn't include the URL, so we can't check if it is a Javascript-built site or not. You'll have to do it. – Tim Roberts Oct 02 '21 at 03:36
  • Your `salaries = soup.find(...)` call is not finding anything and so `salaries` will be `None` to indicate this. In effect you then do `None.text` which causes your error. You either need to test for `None` before using it, or fix your find call. – Martin Evans Oct 02 '21 at 17:48
  • Does this answer your question? [Why do I get AttributeError: 'NoneType' object has no attribute 'something'?](https://stackoverflow.com/questions/8949252/why-do-i-get-attributeerror-nonetype-object-has-no-attribute-something) – Ture Pålsson Aug 21 '22 at 08:17

0 Answers0