1

Hey guys I'am testing a python module named 'webbrowser' but its not giving any responses when I tries to open youtube. Please solve this problem. This is the code.

import webbrowser

webbrowser.open("www.youtube.com")

And I'm not getting any error also. On Printing it is showing :

True

When I tried this code :

import webbrowser
webbrowser.get("google-chrome"),open("https://www.youtube.com")

It gives this error:

webbrowser.get("google-chrome"),open("https://www.youtube.com")  
File "C:\Program Files\Python39\lib\webbrowser.py", line 65, in get
raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser

1 Answers1

1

Please locate your browser path and then register it through document, Then run the webbrowser.

import webbrowser    
urL='https://www.google.com'
chrome_path="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path), 1)
webbrowser.get('chrome').open(urL)
Ali Irani
  • 557
  • 3
  • 10
  • what do You think printing it out will give? – Matiiss Jun 16 '21 at 09:55
  • print it shows if the command runs properly or not. – Ali Irani Jun 16 '21 at 09:57
  • I printed, well for me it shows True, and I guess for OP it could show False but that doesn't help much does it, although sure do that to check if anything happens – Matiiss Jun 16 '21 at 09:58
  • Its giving True here but not working ! Is there any solution ? or How can I put the default browser path in system path. – 17_Ronstark_04 Jun 16 '21 at 11:17
  • If you have firefox test this code: `webbrowser.get("firefox").open("https://www.youtube.com") ` If you have google chrome replace `firefox` with `google-chrome` and see the result. – Ali Irani Jun 16 '21 at 11:23
  • @AliIrani I tried your code and its giving an error that It is not able to locate the browser. Traceback (most recent call last): , line 3, in webbrowser.get("google-chrome"),open("https://www.youtube.com") File "C:\Program Files\Python39\lib\webbrowser.py", line 65, in get raise Error("could not locate runnable browser") webbrowser.Error: could not locate runnable browser – 17_Ronstark_04 Jun 17 '21 at 08:49
  • @AliIrani I also tried to this code with chrome path but its giving the same error. – 17_Ronstark_04 Jun 17 '21 at 08:59
  • Please try with `get('chrome')` and see that works? If not add chrome pass to your os path and check again with `chrome` or `google-chrome` – Ali Irani Jun 17 '21 at 09:31
  • @AliIrani Please can you explain how to add chrome to os path of Windows 10. – 17_Ronstark_04 Jun 18 '21 at 01:39
  • This link seems useful. https://support.leapwork.com/hc/en-us/articles/115001192311-Could-not-open-Chrome-please-check-that-it-is-properly-installed-on-your-computer – Ali Irani Jun 18 '21 at 18:03
  • @AliIrani Bro I have added the chrome to os path but its not giving any output. please tell any other way to solve this problem. – 17_Ronstark_04 Jun 19 '21 at 04:09
  • Did you try both `chrome` & `google-chrome`? – Ali Irani Jun 19 '21 at 08:24
  • @AliIrani Yes I have tried both chrome & google-chrome but its giving the same error that can't find the runnable browser. Can Reinstalling the Python 3.9 solve this Problem. – 17_Ronstark_04 Jun 21 '21 at 03:38
  • I don't think reinstalling python helps. I edited my solution to register the browser in your code. Please try it. – Ali Irani Jun 21 '21 at 07:08
  • @AliIrani I have tried your code its giving this error : webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path), 1) TypeError: register() takes from 2 to 3 positional arguments but 4 were given. Please this Problem – 17_Ronstark_04 Jun 26 '21 at 01:12
  • I figure out maybe our problem is somewhere else. Please try this: `webbrowser.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s").open("http://google.com")` or change that path with your chrome path. Please change all `\\` to one `/` similar to my code – Ali Irani Jun 26 '21 at 11:51
  • @AliIrani I have tried but its not giving any output please tell other solution. Or is there any other method to search through web browser. – 17_Ronstark_04 Jun 27 '21 at 12:55