tags:

views:

43

answers:

2

I need a python script to perform a GET request on 2 urls.

I will use these scripts in a cron job on my ubuntu server.

The catch is, the 2 calls have to happen sequentially because the first GET request to Url#1 might take up to 1 minute or so to complete.

For the cron job, I want it to run every 30 minutes.

A: 

I suggest you read the documentation of urllib:

http://docs.python.org/library/urllib.html

Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> urllib.urlretrieve("http://www.google.com")
('/tmp/tmpfYqXGp', <httplib.HTTPMessage instance at 0x109c878>)
>>> urllib.urlcleanup()
>>> 
omrib
+2  A: 

I'm not sure if I'm missing something in your question. But it should be fairly simple with urllib2:

import urllib2

request = urllib2.Request('http://example.com/path')
response = urllib2.urlopen(request)
content = response.read()

# now make the second request, just as above

See the page, urllib2 The Missing Manual for more help with the urllib2 module.

ars