Aug-17-2020, 02:28 AM
Hi all,
I tried to do web scraping with webdriver from selenium (chromedriver) and BeautifulSoup.
Here I show you my code:
Which attribute I have to put in the append function?
Best regards.
Alexis
I tried to do web scraping with webdriver from selenium (chromedriver) and BeautifulSoup.
Here I show you my code:
from selenium import webdriver from bs4 import BeautifulSoup import pandas as pd driver = webdriver.Chrome("/usr/local/bin/chromedriver") products=[] #List to store name of the product prices=[] #List to store price of the product ratings=[] #List to store rating of the product driver.get("https://www.flipkart.com/search?q=laptop&otracker=search&otracker1=search&marketplace=FLIPKART&as-show=off&as=off") content = driver.page_source soup = BeautifulSoup(content) for a in soup.findAll('a',href=True, attrs={'class':'_31qSD5'}): name=a.find('div', attrs={'class':'_3wU53n'}) price=a.find('div', attrs={'class':'_1vC4OE _2rQ-NK'}) rating=a.find('div', attrs={'class':'hGSR34 _2beYZw'}) products.append(name.text) prices.append(price.text) ratings.append(rating.text) #line 25 df = pd.DataFrame({'Product Name':products,'Price':prices,'Rating':ratings}) df.to_csv('products.csv', index=False, encoding='utf-8')But I obtain this error:
Error:AttributeError: 'NoneType' object has no attribute 'text'
I don't understand why.Which attribute I have to put in the append function?
Best regards.
Alexis