0

I came across another question asking how to open Chrome using webbrowser, and I wanted to do it for myself.

Python webbrowser.open() to open Chrome browser

I have a variable saved in the module called Chrome

Chrome = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %s"

I did this so I could perform this code:

import webbrowser as wb
from webbrowser import Chrome

wb.get(Chrome).open('Google.com')

When I run this code, I get the following error:

Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
wb.get(Chrome).open('google.com')
File "C:\Users\MY USERNAME\AppData\Local\Programs\Python\Python37- 
32\Lib\webbrowser.py", line 50, in get
if '%s' in browser:
TypeError: argument of type 'type' is not iterable

Why isn't this working? I'm running Python 3.7.

0

2 Answers 2

1

You're using Chrome in two different ways:

Chrome = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %s"

and

from webbrowser import Chrome

Since you can't have two things named Chrome in the same namespace, one is clobbering the other. In this case, Chrome from the webbrowser module is clobbering the string pointing to your local Chrome browser.

Use different names for each thing, e.g.

import webbrowser

chrome = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %s'
webbrowser.get(chrome).open('google.com')

Alternatively, something like this will probably work since Python already knows about a bunch of browsers (I don't have a Windows machine to test on right now):

from webbrowser import Chrome

# Find a Chrome-family browser whose binary name is chrome
chrome = Chrome('chrome')  # chrome = Chrome('chromium') works on my Linux machine
chrome.open('google.com')
0

I tried

import webbrowser as wb
Chrome = 'open -a /Applications/Google\ Chrome.app %s'
wb.get(Chrome).open('http://google.com')

and it worked. The differences here are my url and my path. I work on MacOS and so the path my browser is different. Maybe you could check if your browser path is correct?

Can you try this path?

C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s
1
  • 1
    Thanks for the fast response. I tried that code and it yielded the same error. Commented Mar 19, 2019 at 17:09

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.