Can't run python program from xampp command line - python

I write a code in python to scrape some data from a web site using selenium. this code completely work when i run it in system command line . But when i run it from xampp command line it give error and show this message
Traceback (most recent call last): File
"C:\Users\Marajul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py",
line 72, in start
self.process = subprocess.Popen(cmd, env=self.env, File "C:\Users\Marajul\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\Marajul\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:\xampp\htdocs\Dairy\API\toph\python\a.py", line 16, in
driver = Chrome(webdriver) File "C:\Users\Marajul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py",
line 73, in init
self.service.start() File "C:\Users\Marajul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py",
line 81, in start
raise WebDriverException( selenium.common.exceptions.WebDriverException: Message:
'chromedriver3.exe' executable needs to be in PATH. Please see
https://sites.google.com/a/chromium.org/chromedriver/home
from selenium.webdriver import Chrome
import pandas as pd
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="",
database="dairy"
)
mycursor = mydb.cursor()
webdriver = 'chromedriver3.exe'
driver = Chrome(webdriver)
cnt=0
while 1:
page_nb=(str)(cnt);
url = "https://toph.co/submissions/filter?author=590d7d60de14194eb555201c&start="+page_nb+"&verdict="
cnt=cnt+64
driver.get(url)
quotes = driver.find_elements_by_class_name("syncer")
if(len(quotes)==0):
break
for quote in quotes:
row=quote.find_elements_by_tag_name("td")
link=row[2].find_elements_by_tag_name('a')
time1=row[3].find_elements_by_class_name('timestamp')
time=time1[0].get_attribute('data-time')
urlp=""
if(link):
urlp=link[0].get_attribute('href')
sql1="SELECT * FROM submission WHERE id=%s AND oj='toph'"
val1 = (row[0].text,)
mycursor.execute(sql1,val1)
myresult = mycursor.fetchall()
if(len(myresult)==0):
sql="INSERT INTO submission (id,dt,link,name,ver,oj) VALUES (%s,%s,%s,%s,%s,'toph')"
val=(row[0].text,time,urlp,row[2].text,row[7].text)
mycursor.execute(sql, val)
mydb.commit()
print("successfull")
driver.close()
i am not expert in python so please help me to fix this problem :)

Your problem is common "not in PATH" type of problem which is clearly indicated by the error message:
Message: 'chromedriver3.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
And the solution is to either use absolute path to the binary (if you can specify that) or to edit your global env PATH variable and add the location of that binary to it.

I have faced a similar issue, it's looking to be this error is generic to windows, after setting shell=True in subprocess.py I able to resolve it.

Related

Trying to do web scraping with Python, but it doesn't work well

I'm doing a school project and I am trying to scrape data from websites. Basically I'm following a tutorial in edureka - https://www.edureka.co/blog/web-scraping-with-python/#demo
The sample code is like this
from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
driver = webdriver.Chrome("/usr/lib/chromium-browser/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/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)
df = pd.DataFrame({'Product Name':products,'Price':prices,'Rating':ratings})
df.to_csv('products.csv', index=False, encoding='utf-8')
I simplly copied and pasted the sample code to Python to see how it works, and this is what I got
PS D:\COSC2625_Team_Blue> & C:/Users/meowg/AppData/Local/Programs/Python/Python310/python.exe d:/COSC2625_Team_Blue/test.py
d:\COSC2625_Team_Blue\test.py:5: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
Traceback (most recent call last):
File "C:\Users\meowg\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\meowg\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\meowg\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, 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 "d:\COSC2625_Team_Blue\test.py", line 5, in <module>
driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
File "C:\Users\meowg\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Users\meowg\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 89, in __init__
self.service.start()
File "C:\Users\meowg\AppData\Local\Programs\Python\Python310\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://chromedriver.chromium.org/home
Does anyone know what went wrong? I have no idea what happened.
Looks like you just didn't download the file that was included in the tutorial, by the location of /usr/lib/chromium-browser/chromedriver. We can't really help you here, you just have to download the chromedriver.
I would recommend you use python playwright instead of selenium, as it is just a more modern library, with a slightly smaller learning curve, in my opinion, but that's just a recommendation.

Trying to open a webpage using selenium but getting error

I wrote this simple code:
from selenium import webdriver
webdriver.Chrome().get('www.google.co.in')
but I'm getting this error:
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\WebAutomation\venv\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, 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\user\PycharmProjects\WebAutomation\venv\Automation.py", line 2, in <module>
webdriver.Chrome().get('www.google.co.in')
File "C:\Users\user\PycharmProjects\WebAutomation\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Users\user\PycharmProjects\WebAutomation\venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 89, in __init__
self.service.start()
File "C:\Users\user\PycharmProjects\WebAutomation\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://chromedriver.chromium.org/home
Someone please help me. I'm a beginner, please explain/guide in detail (I don't know complex concepts)
You will need additional the Selenium-Chrome-Driver.exe!
The last line of errors tells this to you.
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
The driver itself will be started from your programm and will hold the binding between your program and the browser chrome itself.
The driver.exe can be easily placed in the programm-startup-path (I recommend this for the first steps) or placed where ever you want, but than you must define the special variable of the PATH to the driver.exe.
You can get the driver.exe behind this link:
Main page:
https://chromedriver.chromium.org/getting-started
Download Page:
https://chromedriver.chromium.org/downloads
Please ensure, that your Browser-Version match to the driver-Version.

Error "chromedriver" executable needs to be in PATH [duplicate]

This question already has answers here:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH error with Headless Chrome
(1 answer)
WebDriverException: Message: 'chromedriver' executable needs to be in PATH while setting UserAgent through Selenium Chromedriver python
(1 answer)
Closed 2 years ago.
Thisselenium.common.exceptions.WebDriverException: Message: '' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home problem arises when I try to run this code. I have downloaded the file from the link and unzipped the it to my download folder like shown: C:\Users\Alexandr\Downloads\chromedriver_win32 . Then I put the path to the executable binary (C:\Users\michael\Downloads\chromedriver_win32) into the Environment Variable "Path".
I found the same thread on StackOverflow and they say I should type chromedriver in cmd and get something like this tarting ChromeDriver 2.15.322448, in my case I get "chromedriver" is not inner or outer command(this was a translation from my native language).
What should I do in this case
from selenium import webdriver
from time import sleep
class InstaBot:
def __init__(self, username, password):
self.driver = webdriver.Chrome()
self.driver.get('https://www.instagram.com/?hl=ru')
sleep(2)
self.driver.find_element_by_xpath("//input[#name=\"username\"]") \
.send_keys(username)
self.driver.find_element_by_xpath("//input[#name=\"password\"]") \
.send_keys(password)
self.driver.find_element_by_xpath('//button[#type="submit"]') \
.click()
sleep(4)
self.driver.find_element_by_xpath('//button[contains(text()."Не сейчас")]').click()
InstaBot('_max_leva_', here is my password)
This is error code:
C:\Users\Alexandr\AppData\Local\Programs\Python\Python38-32\python.exe C:/PythonProjects/python/LearningPython/main1.py
Traceback (most recent call last):
File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\Alexandr\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\Alexandr\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] Не удается найти указанный файл
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/PythonProjects/python/LearningPython/main1.py", line 27, in <module>
InstaBot('_max_leva_', '447781470659')
File "C:/PythonProjects/python/LearningPython/main1.py", line 14, in __init__
self.driver = webdriver.Chrome()
File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38-32\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
Process finished with exit code 1
Environment Variable:
%PATH%:C:\Users\Alexandr\Downloads\chromedriver_win32
In the self.driver = webdriver.Chrome(), pass the path to the executable as an argument in the parentheses.
For example:
self.driver = webdriver.Chrome('C:/user/Downloads/chromedriver.exe')

Error while performing OCR using pytesseract

I wanna to use pytesseract. This is my code.
import pytesseract
from pdf2image import convert_from_path
PDF_file = 'file.pdf'
text = ''
pages = convert_from_path(PDF_file, 500)
pageText = str(((pytesseract.image_to_string(pages[0]))))
and at result I get this error
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pdf2image\pdf2image.py", line 409, in pdfinfo_from_path
proc = Popen(command, env=env, stdout=PIPE, stderr=PIPE)
File "C:\Users\user\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\user\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\user\Desktop\projects\pdfparser\pdftest.py", line 13, in
pages = convert_from_path(PDF_file, 500)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pdf2image\pdf2image.py", line 89, in convert_from_path
page_count = pdfinfo_from_path(pdf_path, userpw, poppler_path=poppler_path)["Pages"]
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pdf2image\pdf2image.py", line 430, in pdfinfo_from_path
raise PDFInfoNotInstalledError(
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
As a lot of comments already pointed out, the error message
PDFInfoNotInstalledError( pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
Tells you precisely what went wrong: Poppler is not installed. Please refer to the README for help on that side.
You see, pdf2image is only a wrapper around the pdftoppm command-line utility. On Linux it is installed by default so you would not need to bother with it, but on Windows it is not.

Selenium WebDriverException 'chromedriver.exe' needs to be in PATH

I'm trying to use selenium for a python web scraper but when I try to run the program I get the following error:
/usr/local/bin/python3 /Users/xxx/Documents/Python/hello.py
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/xxx/Documents/Python/chromedriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/xxx/Documents/Python/hello.py", line 9, in <module>
wd = webdriver.Chrome(executable_path=DRIVER_PATH)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Here is the python code:
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
from selenium import webdriver
DRIVER_PATH = '/Users/xxx/Documents/Python/chromedriver.exe'
wd = webdriver.Chrome(executable_path=DRIVER_PATH)
I think the problem is that I'm not specifying the file path in the variable DRIVER_PATH properly but I'm not sure
I am using a Mac
You need to update DRIVER_PATH to include your root directory, which is usually C:\:
DRIVER_PATH = 'C:/Users/xxx/Documents/Python/chromedriver.exe'
Alternatively, you can follow this tutorial to add the path to containing folder of chromedriver.exe (usually chromedriver_win32 folder) to your Path environment variable:
https://docs.telerik.com/teststudio/features/test-runners/add-path-environment-variables
I would try this out (Just adding the 'r'):
wd = webdriver.Chrome(executable_path=r'/Users/xxx/Documents/Python/chromedriver.exe')
if you think it's the filepath then have a go with checking:
import os.path
os.path.exists(DRIVER_PATH)
Also, Beautifulsoup is used will with urllib2
https://www.pythonforbeginners.com/beautifulsoup/beautifulsoup-4-python
import urllib2
url = "https://www.URL.com"
content = urllib2.urlopen(url).read()
soup = BeautifulSoup(content)
You have a mistake in the name of the file.
"chomedriver.exe" is for windows.
If you use macOS and chromedriver for Mac, then the file name should be "chomedriver" without ".exe".
I had the same problem, but this solved it.

Categories