def cachePagePost(url,post):
logger.info("Descargando " + url)
inicio = time.clock()
req = urllib2.Request(url,post)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
try:
response = urllib2.urlopen(req)
except:
req = urllib2.Request(url.replace(" ","%20"),post)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
response = urllib2.urlopen(req)
data=response.read()
response.close()
fin = time.clock()
logger.info("Descargado en %d segundos " % (fin-inicio+1))
'''
outfile = open(localFileName,"w")
outfile.write(data)
outfile.flush()
outfile.close()
logger.info("Grabado a " + localFileName)
'''
return data
评论列表
文章目录