I'm new to python and i'm trying to achieve a web scraping project. I was following a tutorial and got stuck in the part that i pass the data to a csv sheet. I already tried to move some brackets and other structures, but nothing seems to help. See the code attached Thanks for the help, i've been stuck for a couple of hours.
An obs: The command "Dataframe" did not change color, i don't if this makes any difference, but it's good to mention.
import bs4
from bs4 import BeautifulSoup
import pandas
import selenium
from selenium import webdriver
import pandas as pd
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 = webdriver.Chrome(executable_path = r'C:\Users\directory\Desktop\chromedriver.exe')
driver.get("https://www.flipkart.com/laptops/~buyback-guarantee-on-laptops-/pr?sid=6bo%2Cb5g&uniq")
content = driver.page_source
soup = BeautifulSoup(content, 'html.parser')
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(("dd").text)
df = pd.Dataframe(data= {'Product Name': products,'Price': prices,'Rating':ratings})
df.to_csv('products.csv', index=False, encoding='utf-8')
The error:
df = pd.Dataframe(data= {'Product Name': products,'Price': prices,'Rating':ratings})
^
SyntaxError: invalid syntax'''
pddefined ? you're probably missingimport pandas as pdpd.Dataframe, it ispd.DataFrame