在定时任务中使用Python脚本对两个URL进行GET请求
我需要一个Python脚本,用来对两个网址进行GET请求。
我会在我的Ubuntu服务器上用这些脚本设置一个定时任务。
这里有个要求,就是这两个请求必须一个接一个地执行,因为第一个对网址#1的请求可能需要大约1分钟才能完成。
对于这个定时任务,我希望它每30分钟运行一次。
2 个回答
0
我建议你去看看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()
>>>
3
我不太确定我是否理解了你的问题。不过,使用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
想要更多关于urllib2模块的帮助,可以查看这个页面:urllib2 缺失手册。