Using Python to start a browser (Chromium) and change the url
I am trying to write a script that makes it possible to change the url of an active process.
So for instance, I am starting my browser using:
browser = Popen(["chromium", "http://www.google.com"])
After an X interval I want to change the url of browser.
I've tried allot of things to get this result but nothing has succeeded so far. (stdin.write / put (PIPE) etc etc.).
browser = sh.Command('uzbl-browser')(print_events=True, config='-', uri=current_browser_url, _bg=True) browser.process.stdin.put('uri http://www.google.nl' + '\n')
I'm hoping you can help me out with this.
if you work with browsers + python, you'll probably want to take a look at Selenium. It's not copy-paste but you can learn it in couple of hours...
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
Here's 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)
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 >>
:: 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.