Jun-09-2020, 01:37 PM
Running code to scrape items from the website and display it
from selenium import webdriver from bs4 import BeautifulSoup import pandas as pd driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver") products= [] prices = [] ratings = [] driver.get("https://www.flipkart.com/laptops/~buyback-guarantee-on-laptops-/pr?sid=6bo%2Cb5g&uniq") 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)However an error comes :
Error:runfile('/Users/aarav/Documents/MyProject/Python/Web_scraping.py', wdir='/Users/aarav/Documents/MyProject/Python')
Traceback (most recent call last):
File "/Users/aarav/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Users/aarav/opt/anaconda3/lib/python3.7/subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "/Users/aarav/opt/anaconda3/lib/python3.7/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/chromium-browser/chromedriver': '/usr/lib/chromium-browser/chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/aarav/Documents/MyProject/Python/Web_scraping.py", line 7, in <module>
driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
File "/Users/aarav/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/Users/aarav/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
What happened?