Python Forum

Full Version: How to open a list of websites
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Could someone please help,

web_value.txt:
http://google.com
http://YouTube.com
openwebsites.py:

import webbrowser
import os


def websites():
    websitelist = "Setup1\\web_value.txt"
    websites = []
    browser = webbrowser.get("windows-default")
    for line in open(websitelist, "r").readlines():
        websites.append(line.strip())
    for website in websites:
        browser.open(website)
websites()
The script opens the websites in my browser and it works perfectly but it also keeps opening the directory of openwebsites.py in file explorer. Is there a way I can get the list of websites from the file and open them in the browser without opening the directory of openwebsites.py in file explorer also. I’m using VSCode
Works ok for me on Windows, maybe there is a blank line at the end of your text file or something like that ?
use: page = browser.page_source
to get browser contents
(Aug-05-2021, 09:54 AM)Larz60+ Wrote: [ -> ]use: page = browser.page_source
to get browser contents
This is not Selenium Larz60+ Wink

So it's a duplicate of this Thread .
(Jul-28-2021, 09:03 PM)Tyrel Wrote: [ -> ]but it also keeps opening the directory of openwebsites.py in file explorer
How do you run this code❔
There is no way i get file explorer to open when i run this code.
It's not a normal behavior as i have run webbrowser on different Pc and Windows version and never has file explorer opened.
Please, don't start multiple threads for the same problem. I will now close this thread. Please, keep the discussion in the original thread
https://python-forum.io/thread-34393.html