2

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?

goldilocks
60.4k17 gold badges117 silver badges236 bronze badges
asked May 27, 2017 at 0:24
1
  • Having looked at some example code most people have the URL directly located in driver.get (). E.g: driver.get("http://icy-e-bz-04-cr.sharp-stream.com/planetrock.mp3"). That might be worth a try. Commented May 27, 2017 at 10:16

4 Answers 4

2

You can also try shell/command line syntax via python

chromium-browser <web_url> <web_url> <web_url>

works on raspbian

answered May 27, 2017 at 11:41
1

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)
answered Apr 12, 2019 at 11:56
1
  • Is it possible to close the window also form python? Commented Apr 2, 2021 at 11:36
0

I had similar problems on a Raspberry B+ with Stretch. I could solve the issues by

  1. creating a symlink named 'google-chrome' pointing to '/usr/lib/chromium-browser/chromium-browser'
  2. 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

Ingo
43k20 gold badges87 silver badges207 bronze badges
answered Dec 20, 2018 at 8:48
10
  • 1
    Doesn't work because there is an indention error in the for loop. Commented 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) Commented Dec 21, 2018 at 4:39
  • 1
    Use 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 errors Commented Dec 21, 2018 at 4:55
  • I have formated the code. Please check it. For what is delay = 5? It isn't used. Commented 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! Commented Dec 21, 2018 at 12:40
0

for /usr/bin/xdg-open: 811: : Permission denied

import os
os.system("chromium https://mesebilisim.com")

works.

goldilocks
60.4k17 gold badges117 silver badges236 bronze badges
answered Apr 22, 2024 at 12:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.