I'm looking to see if its somehow to possible to open a file containing multiple URLs and open them all in a browser. The text file contains 200+ lines and each line is a unique URL.
Asked
Active
Viewed 640 times
-3
-
3Of course it's possible. – karakfa Oct 26 '15 at 21:48
-
1We might need to know what operating system and browser you are wanting to use. Some operating systems might be able to launch a URL directly with a default browser. On others, you may need to figure out where the web browser lives and want command line arguments are required to have it launch and navigate to the given URL. Also, are you wanting them to open in tabs vs windows? – Jeff B Oct 26 '15 at 21:49
-
They how would you do this in Python? – user181895 Oct 26 '15 at 21:49
-
@user181895 have you considered learning to write Python code and then doing so? – jonrsharpe Oct 26 '15 at 21:50
-
2Also, you have several problems here: [1] opening a file, [2] iterating over the lines in a file, and [3] opening a string URL in a browser. Try searching for ways to solve each one.... then put them together. – Jeff B Oct 26 '15 at 21:50
-
@JeffBridgman: OS is Windows / Preferable browser is Chrome. I will do so. Thanks – user181895 Oct 26 '15 at 21:51
-
Possible duplicate: http://stackoverflow.com/q/31715119/945456 – Jeff B Oct 26 '15 at 21:53
-
3Have you considered using PowerShell? `gc .\urls.txt |% { start chrome "$_" }` – TessellatingHeckler Oct 26 '15 at 21:54
-
@TessellatingHeckler: I had not considered using powershell and that command did exactly what I was as looking to accomplish. Thank you. – user181895 Oct 26 '15 at 22:02
2 Answers
3
Use webbrowser
module.
import webbrowser
with open("filename","r") as f:
for url in f:
webbrowser.open_new_tab(url)
This will open the url
s in new tab one by one.
You can learn in detail about webbrowser
module from Here

Ahsanul Haque
- 10,676
- 4
- 41
- 57
0
Iterate through the lines and using webbrowser do something like this
import webbrowser
webbrowser.open('http://example.com')

user3307291
- 708
- 1
- 8
- 11