【发布时间】:2012-03-08 06:45:51
【问题描述】:
我正在尝试从 Google 图片搜索中获取特定查询的图片。但是我下载的页面没有图片,它会将我重定向到谷歌的原始页面。这是我的代码:
AGENT_ID = "Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
GOOGLE_URL = "https://www.google.com/images?source=hp&q={0}"
_myGooglePage = ""
def scrape(self, theQuery) :
self._myGooglePage = subprocess.check_output(["curl", "-L", "-A", self.AGENT_ID, self.GOOGLE_URL.format(urllib.quote(theQuery))], stderr=subprocess.STDOUT)
print self.GOOGLE_URL.format(urllib.quote(theQuery))
print self._myGooglePage
f = open('./../../googleimages.html', 'w')
f.write(self._myGooglePage)
我做错了什么?
谢谢
【问题讨论】:
-
至少你要关闭文件句柄
-
@silviolor:我知道这对您的问题没有帮助,但为什么不使用 python 的内置
urllib2模块而不是curl。