Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script to connect to a web page

Tags:

python

Looking for a python script that would simply connect to a web page (maybe some querystring parameters).

I am going to run this script as a batch job in unix.

like image 376
mrblah Avatar asked Dec 19 '25 02:12

mrblah


2 Answers

urllib2 will do what you want and it's pretty simple to use.

import urllib
import urllib2

params = {'param1': 'value1'}

req = urllib2.Request("http://someurl", urllib.urlencode(params))
res = urllib2.urlopen(req)

data = res.read()

It's also nice because it's easy to modify the above code to do all sorts of other things like POST requests, Basic Authentication, etc.

like image 143
Mark Biek Avatar answered Dec 20 '25 18:12

Mark Biek


Try this:

aResp = urllib2.urlopen("http://google.com/");
print aResp.read();
like image 31
NawaMan Avatar answered Dec 20 '25 19:12

NawaMan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!