I'm using the google AIY voice project for the Raspberry Pi that came with magpi issue 57. I have had a lot of success despite being new to pi's which is nice.
I'm struggling to open chromium-browser so that automatically goes to a URL I give it. After searching on the internet I started using selenium and managed to get the browser to open but it wont go to any URL I pass. The current code in my Python file is:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
station = 'http://icy-e-bz-04-cr.sharp-stream.com/planetrock.mp3'
driver = webdriver.Chrome(executable_path="/usr/lib/chromium-browser/chromium-browser")
driver.get(station)
This half works and opens chromium but doesn't then go to the 'station' I provided. Any ideas on how to fix this?
4 Answers 4
You can also try shell/command line syntax via python
chromium-browser <web_url> <web_url> <web_url>
works on raspbian
Follow this code to get your code worked.
import webbrowser, os, sys
url = "http://192.168.2.128:5008/"
chrome_path = '/usr/lib/chromium-browser/chromium-browser'
webbrowser.get(chrome_path).open(url)
-
Is it possible to close the window also form python?André Clérigo– André Clérigo2021年04月02日 11:36:09 +00:00Commented Apr 2, 2021 at 11:36
I had similar problems on a Raspberry B+ with Stretch. I could solve the issues by
- creating a symlink named 'google-chrome' pointing to '/usr/lib/chromium-browser/chromium-browser'
- replacing "driver." in the python-code with "browser." as example below:
Example:
#!/usr/bin/env python3
import time
from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import B
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
usernameStr = 'abcdef'
passwordStr = 'uvwzyx'
findStr1 = 'Welcome abcdef!'
findStr2 = 'Password'
driver = '/usr/lib/chromium-browser/chromedriver'
chrome_options = Options()
chrome_options.binary_location = "/usr/lib/chromium-browser/chromium-browser"
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.get(('http://192.168.88.1/status'))
delay = 5
for element in browser.find_elements_by_xpath("//*[contains(text(), findStr1)]"):
et = element.text
print (et)
if et == findStr1:
print ("already connected")
break
elif et.find(findStr2):
print ("not connected yet")
break
In case I would replace 'browser' with 'driver' I would get tons of errors. I was close to give up because elsewhere I found statements, that selenium dos not support raspberry resp chromium-browser anymore.
I am using a script to auto-connect after boot to the wifi network in my apartment. The lines above are the first commands.
In case of 'connection' (that happens sometimes) the script stops.
In case of 'no connection' the login-form is being filled and submitted by further code, which is not displayed here.
Not 100% your question but you might give this a try.
cheers
-
1Doesn't work because there is an indention error in the for loop.Ingo– Ingo2018年12月20日 09:57:38 +00:00Commented Dec 20, 2018 at 9:57
-
This problem might be due to the formatting options in mini-Markdown formatting options of this webpage. (I have to use 4 spaces to display the code)MikeOffenbach– MikeOffenbach2018年12月21日 04:39:21 +00:00Commented Dec 21, 2018 at 4:39
-
1Use a code editor like i.E "IDLE" to debug this code or a text-editor and replace blanks in indentation. Indentation needs to be done with tabs instead of blanks. Mixing tabs and spaces causes errorsMikeOffenbach– MikeOffenbach2018年12月21日 04:55:06 +00:00Commented Dec 21, 2018 at 4:55
-
I have formated the code. Please check it. For what is
delay = 5
? It isn't used.Ingo– Ingo2018年12月21日 11:42:54 +00:00Commented Dec 21, 2018 at 11:42 -
use Python3 IDLE! load the code with 'file open' and click on 'run Check Module'. In case of no errors run the code!MikeOffenbach– MikeOffenbach2018年12月21日 12:40:54 +00:00Commented Dec 21, 2018 at 12:40
for /usr/bin/xdg-open: 811: : Permission denied
import os
os.system("chromium https://mesebilisim.com")
works.
driver.get ()
. E.g:driver.get("http://icy-e-bz-04-cr.sharp-stream.com/planetrock.mp3")
. That might be worth a try.