linux – Using Python to start a browser (Chromium) and change the url

linux – Using Python to start a browser (Chromium) and change the url

I recommend using selenium to automate this process although you could use webbrowser too:

from selenium.webdriver import *;

chrome = Chrome() # create browser
chrome.get(http://www.google.com)

Just import webbrowser and use function webbrowser.open

Heres an example of opening a music playlist:

import webbrowser
gaana= http://gaana.com/playlist/gaana-dj-bollywood-top-50-1
webbrowser.open_new_tab(gaana)

linux – Using Python to start a browser (Chromium) and change the url

i am working on ubuntu 16.04 and i solve this problem by using geckodriver.exe file. these steps are very simple please read caefully.

:: at first you have to install selenium by typing this command on terminal>>

        for python2:-  python -m pip install --user selenium
        for python3:-  python3 -m pip install --user selenium

:: next step download geckodriver using link given below >>

       https://github.com/mozilla/geckodriver/releases

:: since i am using ubuntu so i download geckodriver-v0.24.0-linux64.tar.gz
now extract it.

:: now in the python code for firefox browsing add these lines >>

 from selenium import webdriver

 browser = webdriver.Firefox(executable_path = /home/aman/Downloads/geckodriver)
 url = str(raw_input(enter a valid url :: ))
 browser.get(url) #example :: url = https://www.google.com
 browser.close()

::for chrome browser >>

 from selenium import webdriver

 browser = webdriver.chrome(executable_path = /home/aman/Downloads/geckodriver)
 url = str(raw_input(enter a valid url :: ))
 browser.get(url) #example :: url = https://www.google.com
 browser.close()

:: in my pc i extract geckodriver in /home/aman/Downloads/geckodriver so you have to put whole path for geckodriver file where you extract your file.

:: now run this python file on python2.7,for python3 replace raw_input with input. i hope this will definitely work for you.

Leave a Reply

Your email address will not be published.