【发布时间】:2013-03-11 23:11:15
【问题描述】:
我在我的网站上创建了一个页面http://shedez.com/test.html 这个页面将用户重定向到我服务器上的 jpg
我想使用 python 脚本将此图像复制到我的本地驱动器。我希望 python 脚本先转到主 url,然后再转到图片的目标 url
然后复制图像。到目前为止,目标网址是硬编码的,但将来它将是动态的,因为我将使用地理编码通过 ip 查找城市,然后将我的用户从他们的城市重定向到当天的图片。
== 我现在的脚本 ===
import urllib2, os
req = urllib2.urlopen("http://shedez.com/test.html")
final_link = req.info()
print req.info()
def get_image(remote, local):
imgData = urllib2.urlopen(final_link).read()
output = open(local,'wb')
output.write(imgData)
output.close()
return local
fn = os.path.join(self.tmp, 'bells.jpg')
firstimg = get_image(final_link, fn)
【问题讨论】:
标签: python