【问题标题】:Google app engine lxml error on production谷歌应用引擎 lxml 生产错误
【发布时间】:2012-11-09 23:32:08
【问题描述】:

我在 Google App Engine 上使用 lxml 来抓取一些基本数据。

它适用于 SDK。当我尝试在我得到的 appengine 服务器上使用它时。

IOError: Error reading file 'http://www.google.com': failed to load external entity "http://www.google.com"

我的代码是这样的;

import lxml.html
url = "http://www.google.com"
t = lxml.html.parse(url)
pagetitle = t.find.(".//title").text
self.response.out.write(pagetitle)

编辑: 我最终不得不做出一个小的改变来处理,如下面的答案所述。

from google.appengine.api import urlfetch
result = urlfetch.fetch(url)
t = lxml.html.fromstring(result.content)

【问题讨论】:

    标签: google-app-engine lxml


    【解决方案1】:

    GAE 不支持打开套接字,您应该使用urlfetch.fetch() 获取页面内容,然后将其提供给解析器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多