Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open URL "silently" in python or similar

Is there anyway to open a URL in Python without opening a tab in a browser?

I have a preconstructed URL which I would like to run when the computer is idle e.g. http://foo.com/bar

I've been able to use the start and webbrowser methods but these open a new tab in my browser.

F.Y.I. The URL returns a blank page with nothing more than the word OK which I don't need.

Could anyone suggest any other way like via a batch or any other program that could do this?

like image 645
Ari Avatar asked Jul 12 '13 12:07

Ari


People also ask

What is URL How can we read URL in Python?

A Uniform Resource Locator (URL) is actually a web address to open a specific site. Sometimes while working in python we need to fetch data from a website, for this we have to open the url of a specific website. So, to open a URL in python we need to import the specified module and perform some steps to open that URL.


1 Answers

Use urllib (Python 2.x):

import urllib
urllib.urlopen('http://foo.com/bar')

(Python 3.x)

import urllib.request
urllib.request.urlopen('http://foo.com/bar')
like image 127
falsetru Avatar answered Oct 22 '22 15:10

falsetru