Forums

Possible errors relating to chrome web driver, unsure

Hi everyone,

First of all i would like to say i am not a professional programmer or someone who has knowledge equivalent to something similar, i have just taken a few computer science courses throughout university. regardless, i have a webscrapping program which works just fine and on the web when tested locally. I even got it to run on pythonanywhere, but when you try to actually do its job, it gives the same error. Basically, the program takes english input from the user, sends it to google translate to get it in punjabi in the indian script, then i take the indian script, i send it to a site which converts it to shahmukhi, the script used in pakistan for punjabi, and it returns it. locally, this works perfectly. on the site, this is the error i keep getting when you click the "translate" button in the logs. i am assuming something is wrong with chrome web driver but unsure how to fix it. any help would be greatly appreciated, thank you. i am sorry about the formatting of this post, the code looks weird i tried to use ctrl k to input it.

Here is the site: http://zr239.pythonanywhere.com/

ERROR LOG

023-03-09 22:03:48,420: Exception on / [POST]

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) File "/home/zr239/mysite/app.py", line 24, in translate trez = webdriver.Chrome(options=options) File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in init super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog", File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 92, in init RemoteWebDriver.init( File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 275, in init self.start_session(capabilities, browser_profile) File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 365, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 430, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.) Stacktrace:

0 0x55aa44d33e89 <unknown>

NO MATCH

This is my python flask code.

from flask import Flask, render_template, request

from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC import time

app = Flask(name)

@app.route('/') def index(): return render_template('index.html')

@app.route('/', methods=['POST']) def translate(): input_text = request.form['input_text']

options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
options.add_argument('headless')

trez = webdriver.Chrome(options=options)
trez.get(
    'https://www.google.com/search?q=english+to+punjabi&rlz=1C1YTUH_enCA1003CA1003&oq=english+to+punjabi&aqs=chrome.0.69i59j0i20i263i512j0i512l3j69i60l3.2256j1j7&sourceid=chrome&ie=UTF-8')

punjabi = trez.find_element("xpath", '//*[@id="tw-source-text-ta"]')
punjabi.send_keys(input_text)

m = WebDriverWait(trez, 10)

time.sleep(5)

gtrans = WebDriverWait(trez, 30).until(
    EC.visibility_of_element_located((By.XPATH, '//*[@id="tw-target-text"]/span')))

gtrans = gtrans.text.strip()

Gurmukhi_text = gtrans

options = webdriver.ChromeOptions()
options.add_argument('headless')

web = webdriver.Chrome(options=options)
web.get('https://sangam.learnpunjabi.org/')

d = WebDriverWait(web, 5)

select = web.find_element("xpath", '//*[@id="Form1"]/div[3]/div[4]/div[1]/div/div[1]/div[1]/nav/div/div[2]/ul/li/a')
select.click()

gurtosh = web.find_element("xpath",
                           '//*[@id="Form1"]/div[3]/div[4]/div[1]/div/div[1]/div[1]/nav/div/div[2]/ul/li/ul/li[11]/a')
gurtosh.click()

gur = web.find_element("xpath", '//*[@id="txtUrdu"]')
gur.send_keys(Gurmukhi_text)

ggg = WebDriverWait(web, 5)

time.sleep(3)

button = web.find_element("xpath", '/html/body/form/div[3]/div[4]/div[1]/div/div[3]/div[3]/h3/input')
button.click()

e = WebDriverWait(web, 5)

# wait until the output box is visible
output_box = WebDriverWait(web, 6).until(EC.visibility_of_element_located((By.ID, "tejout")))

# wait for the output box to load its content
time.sleep(3)

# get the output text
output_text = output_box.text.strip()

return render_template('index.html', output_text=output_text)

if name == 'main': app.run(debug=True)

Make sure to include all the options from an example presented here: https://help.pythonanywhere.com/pages/selenium