How to open a website in google chrome using webbrowser module
I am trying to open a website from python in google chrome, but when I run this code -
import webbrowser
webbrowser.open('youtube.com')
It opens Youtube in edge browser. Then I tried to change the default browser, but it still didn't work, so I ran this code:
import webbrowser
webbrowser.get('C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s').open('youtube.com')
But this code didn't give any output. So how can I open a website in google chrome using python.
1 answer
-
answered 2022-05-04 11:11
arya sianati
Try this:
import webbrowser url = "https://www.youtube.com/" webbrowser.open(url)
I use
https://www.youtube.com/
instead ofyoutube.com
and it will works :)
do you know?
how many words do you know
See also questions close to this topic
-
Python File Tagging System does not retrieve nested dictionaries in dictionary
I am building a file tagging system using Python. The idea is simple. Given a directory of files (and files within subdirectories), I want to filter them out using a filter input and tag those files with a word or a phrase.
If I got the following contents in my current directory:
data/ budget.xls world_building_budget.txt a.txt b.exe hello_world.dat world_builder.spec
and I execute the following command in the shell:
py -3 tag_tool.py -filter=world -tag="World-Building Tool"
My output will be:
These files were tagged with "World-Building Tool": data/ world_building_budget.txt hello_world.dat world_builder.spec
My current output isn't exactly like this but basically, I am converting all files and files within subdirectories into a single dictionary like this:
def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree
Right now, my dictionary looks like this:
key:''
.In the following function, I am turning the empty values
''
into empty lists (to hold my tags):def empty_str_to_list(d): for k,v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v)
When I run my entire code, this is my output:
hello_world.dat ['World-Building Tool'] world_builder.spec ['World-Building Tool']
But it does not see
data/world_building_budget.txt
. This is the full dictionary:{'data': {'world_building_budget.txt': []}, 'a.txt': [], 'hello_world.dat': [], 'b.exe': [], 'world_builder.spec': []}
This is my full code:
import os, argparse def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree def empty_str_to_list(d): for k, v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v) parser = argparse.ArgumentParser(description="Just an example", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("--filter", action="store", help="keyword to filter files") parser.add_argument("--tag", action="store", help="a tag phrase to attach to a file") parser.add_argument("--get_tagged", action="store", help="retrieve files matching an existing tag") args = parser.parse_args() filter = args.filter tag = args.tag get_tagged = args.get_tagged current_dir = os.getcwd() files_dict = fs_tree_to_dict(current_dir) empty_str_to_list(files_dict) for k, v in files_dict.items(): if filter in k: if v == []: v.append(tag) print(k, v) elif isinstance(v, dict): empty_str_to_list(v) if get_tagged in v: print(k, v)
-
Actaully i am working on a project and in it, it is showing no module name pip_internal plz help me for the same. I am using pycharm(conda interpreter
File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\Scripts\pip.exe\__main__.py", line 4, in <module> File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\__init__.py", line 4, in <module> from pip_internal.utils import _log
I am using pycharm with conda interpreter.
-
Looping the function if the input is not string
I'm new to python (first of all) I have a homework to do a function about checking if an item exists in a dictionary or not.
inventory = {"apple" : 50, "orange" : 50, "pineapple" : 70, "strawberry" : 30} def check_item(): x = input("Enter the fruit's name: ") if not x.isalpha(): print("Error! You need to type the name of the fruit") elif x in inventory: print("Fruit found:", x) print("Inventory available:", inventory[x],"KG") else: print("Fruit not found") check_item()
I want the function to loop again only if the input written is not string. I've tried to type return Under print("Error! You need to type the name of the fruit") but didn't work. Help
-
i run dotnet "hello world" from command line, how do i continue to run app from github
new to dotnet
my primary goal is running this repo from github that allows you to automate downloads from soulseek (music sharing service).
my end goal is to automate a pipeline in which i extract song lists from my spotify (using python and spotipy) and download them at high quality from soulseek. (i'm aware of the option to download directly with python from youtube, don't like the quality of output)
what i did so far:
installed dotnet-sdk-6.0
run "hello world"
created new "webapp" project (here's already a question, is that the correct project type to choose?)
4.installed soulseek package available at nuget (link in the repo) with add package command
dotnet run
all that resulted in a clean web page with no sign of soulseek. not sure how to continue.
bottom line, i would appreciate an overview of the steps i should take. it's not very clear. especially, where is the first steps in the repo (after installing nuget which i think i passed successfully) take place?
specifically, where to i type these lines?? (and other lines following)
var client = new SoulseekClient(); await client.ConnectAsync("Username", "Password");
-
Trying to open multiple urls in the same window with webbrowser
I'm trying to open multiple urls in the same window with webbrowser Is there a cleaner way to write rewrite this script? possibly defining a list that can be opened in new tabs with webrowser module?
I attempted this below but the output is all the urls crammed into one tab :
import webbrowser websites = ['www.google.com', 'www.reddit.com'] for url in websites: webbrowser.open_new_tab(url)
Is there a way to rewrite my script cleaner, the way i got it to work just looks complex( Sorry if my question comes off wrong i am still new to python learning ) [Original Script]
import webbrowser import colorama from colorama import Fore from colorama import Style # [ COLOR LEGEND : ] colorama.init(autoreset=True) RED = Fore.RED BLUE = Fore.CYAN MAG = Fore.MAGENTA RESET = colorama.Fore.RESET LIT = Style.BRIGHT print(f'{RED}{LIT}TABLE OF CONTENTS:') print(f'{RED}{LIT}cstop(c):{RESET} The Basics ') print(f'{RED}{LIT}tech(t):{RESET} Tech related News ') print(f'{RED}{LIT}Xtras(x):{RESET} All the Extras ') def Cstop_news(): choice = input(f'What Section of news would you like to read? \n [Enter the Letter]: ') if choice == 'c': webbrowser.open_new_tab('https://www.google.com/') webbrowser.open_new_tab('https://www.google.com/') webbrowser.open_new_tab('https://www.google.com/') elif choice == 't': webbrowser.open_new_tab('https://krebsonsecurity.com/') webbrowser.open_new_tab('https://www.google.com/') webbrowser.open_new_tab('https://www.google.com/') elif choice == 'x': webbrowser.open_new_tab('https://www.google.com/') webbrowser.open_new_tab('https://www.google.com/') webbrowser.open_new_tab('https://www.google.com/') webbrowser.open_new_tab('https://www.google.com/') webbrowser.open_new_tab('https://www.google.com/') webbrowser.open_new_tab('https://www.google.com/') else: print('It seems you made a typo, that section does not exist') Cstop_news()
- R 4.2.0 doesn't start in RStudio (Windows 11)
-
Windows 11 VPN connects but loses Internet
I am not 100% sure it is specifically Windows 11 related, just that I also have a Windows 10 computer and the VPN works OK on that. Also, it used to work on my Windows 11 computer.
I have tried the built in Windows VPN, OpenVPN and the VPN supplied as part of Norton 360. In all case the VPN connects OK but then either immediately or shortly afterwards I lose Internet connection.
Sometimes, disconnecting and reconnecting works and I get Internet connection back for a short while (a few minutes?) but usually I need to restart my computer.
I thought it was possibly a setup problem initially, but if using Norton's VPN does the same thing then it has to be a Windows issue?
I would expect Norton VPN to just work - it does connect but I lose Internet. Their help forum has no useful help.
The specific VPN provider I am trying to connect to works fine from other computers, so it is not an issue with their system.
The VPN connection used to work on the Windows 11 computer but has stopped working recently. (I don't need to use it all of the time)
I have talked through the setup with the support department of the VPN supplier and it still doesn't work.
I have searched Google and tried rebooting, checked all settings (that I can find / know of), ensured Windows is up to date.
I can consistently (re)start my computer, immediately connect to the VPN (Windows or OpenVPN) and get a working connection for a short while (testing using Postman and via Chrome) to the endpoint I need to connect to. After a undeterminable period of time (or after something else happens), I then lose Internet connection. Restarting the VPN sometimes works but usually I have to restart the computer.
I am at a loss about what else to try - apart from downgrading to Windows 10 or trying to reinstall Windows 11.
If I am not providing enough information here, or showing that I've investigated and tried everything, please let me know what else I should do.
-
vmware Virtualization in Windows 11
after updating to windows 11, when i try to open a virtual machine in VMWare WorkStation it give me this error message in the photo. After i've update to windows 11 the virualization isn't work it enabled from bios but the virtual machine couldn't access. i'm sure that i had enabled the Virtualization from bios but the error still. And i've make sure the settings again . I tried to disable and enable it again but no thing changed. this is the error message enter image description here
Any one know about how to solve the problem And make the vm can access to virtualization . Thanks