NoneType object has no attribute text

0 votes
from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
driver = webdriver.Chrome("D:/chromedriver")
products=[] #List to store name of the product
prices=[] #List to store price of the product
Descriptions=[] #List to store rating of the product
driver.get("https://www.nike.com/w/womens-lifestyle-shoes-13jrmz5e1x6zy7ok")
content = driver.page_source
soup = BeautifulSoup(content)
for a in soup.find_all('a',href=True, attrs={'class':'product-card__link-overlay'}):
    name = a.find('div', attrs={'class':'product-card__title'})
    price=a.find('div', attrs={'class':'product-card__price'})
    products.append(name.text)
    prices.append(price.text)
    Descriptions=a.find('li', attrs={'class':'product-card__subtitle'}) 
    #ratings.append(rating.text) 
df = pd.DataFrame({'Product Name':products,'Price':prices, 'Description' :Descriptions}) 
#,'Rating':ratings
df.to_csv('scraping .csv', index=False, encoding='utf-8')




AttributeError                            Traceback (most recent call last)
<ipython-input-38-5c26eac7db21> in <module>
      6     price=a.find('div', attrs={'class':'product-card__price'})
      7     #rating=a.find('div', attrs={'class':'_3LWZlK'})
----> 8     products.append(name.text)
      9     prices.append(price.text)
     10     Decsriptions=a.find('li', attrs={'class':'product-card__subtitle'})

AttributeError: 'NoneType' object has no attribute 'text'
Dec 7, 2020 in Python by Muhammad Umer
• 120 points
27,460 views

1 answer to this question.

0 votes

Hello @Muhammad Umer,

As per the Beautiful Soup Documentation:

AttributeError: 'NoneType' object has no attribute 'foo' - This usually happens because you called find() and then tried to access the .foo attribute of the result. But in your case, find() didn’t find anything, so it returned None, instead of returning a tag or a string. You need to figure out why your find() call isn’t returning anything.

It could not find an element you searched for at this line, and returned None: post_title = post.find(class_='a-section').text

answered Dec 7, 2020 by Niroj
• 82,840 points

Related Questions In Python

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

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

Hi@akhtar, It seems Sklearn is not installed properly ...READ MORE

answered Jun 23, 2020 in Python by MD
• 95,460 points
7,481 views
0 votes
0 answers

OpenCV NoneType object has no attribute shape

I  am working on Raspberry Pi with ...READ MORE

May 9, 2022 in Python by Kichu
• 19,040 points
3,113 views
0 votes
1 answer

How to use BeautifulSoup for Webscraping

Your code is good until you get ...READ MORE

answered Sep 6, 2018 in Python by Priyaj
• 58,020 points
2,194 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,020 points
1,699 views
0 votes
1 answer

How to download intext images with beautiful soup

Try this: html_data = """ <td colspan="3"><b>"Assemble under ...READ MORE

answered Sep 10, 2018 in Python by Priyaj
• 58,020 points
5,473 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,020 points
873 views
0 votes
1 answer

Error:AttributeError: 'NoneType' object has no attribute 'extend'

Hello @kartik, You can use itertools.chain(): import itertools list2d = [[1,2,3], ...READ MORE

answered Nov 18, 2020 in Python by Niroj
• 82,840 points
3,618 views
0 votes
2 answers

Python Pandas error: AttributeError: 'DataFrame' object has no attribute 'rows'

Try this: data=pd.read_csv('/your file name', delim_whitespace=Tru ...READ MORE

answered Dec 10, 2020 in Python by anonymous
• 82,840 points
132,759 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP