Selenium won't open a link - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Selenium won't open a link (/thread-25656.html) |
Selenium won't open a link - Justin2444 - Apr-07-2020 My code is: from selenium import webdriver class Bot: def __init__(self): self.driver = webdriver.Chrome() self.driver.get("https://instagram.com") Bot() I get errors in lines that don't exist. The errors are incredibly long and I assume it is errors with webdriver code but I'm not sure. Here are the errors: Traceback (most recent call last): File "C:\Users\Justin\PycharmProjects\Instagram bot\venv\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start self.process = subprocess.Popen(cmd, env=self.env, File "C:\Users\Justin\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\Justin\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] The system cannot find the file specified During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/Justin/PycharmProjects/Instagram bot/Bot.py", line 10, in <module> Bot() File "C:/Users/Justin/PycharmProjects/Instagram bot/Bot.py", line 6, in __init__ self.driver = webdriver.Chrome() File "C:\Users\Justin\PycharmProjects\Instagram bot\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__ self.service.start() File "C:\Users\Justin\PycharmProjects\Instagram bot\venv\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start raise WebDriverException( selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home Anyone know how to fix this? RE: Selenium won't open a link - snippsat - Apr-07-2020 (Apr-07-2020, 03:51 AM)Justin2444 Wrote: selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please seBye this mean that chromedriver.exe must be in Environment Variables Path.Driver can also be in same folder as you run script,that will also work. Here a typical setup where set executable_path and options (where can eg set headless).So C:\cmder\bin folder is in my Windows Path.from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys from bs4 import BeautifulSoup import time #--| Setup options = Options() options.add_argument("--headless") options.add_argument('--disable-gpu') options.add_argument('--log-level=3') browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options) #--| Parse or automation browser.get('https://www.morningstar.com/stocks/XOSL/XXL/quote.html') time.sleep(1) soup = BeautifulSoup(browser.page_source, 'lxml') price_sales = soup.select('li:nth-child(9) > div > div.dp-value.ng-binding') print(price_sales[0].text.strip())
RE: Selenium won't open a link - Larz60+ - Apr-07-2020 FYI if using virtual environment, I usually put the drivers in the venv/bin directory. This way they are always accessible by the software |