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?

  • 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. – Darth Vader May 27 '17 at 10:16
1

You can also try shell/command line syntax via python

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

works on raspbian

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)
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

  • 1
    Doesn't work because there is an indention error in the for loop. – Ingo Dec 20 '18 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 Dec 21 '18 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 – MikeOffenbach Dec 21 '18 at 4:55
  • I have formated the code. Please check it. For what is delay = 5? It isn't used. – Ingo Dec 21 '18 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 Dec 21 '18 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.