本文介绍了Python 机械化 + GAEpython 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道之前关于机械化 + Google App Engine 的问题,我应该使用什么纯 Python 库来抓取网站?机械化和 Google App Engine.

I am aware of previous questions regarding mechanize + Google App Engine,What pure Python library should I use to scrape a website?and Mechanize and Google App Engine.

还有一些代码这里,我无法得到在应用引擎上工作,抛出

Also there is some code here, which I cannot get to work on app engine, throwing

File "D:dataeclipse-php	estpy4srcmechanize\_http.py", line 43, in socket._fileobject("fake socket", close=True)
File "C:Program Files (x86)Googlegoogle_appenginegoogleappenginedistsocket.py", line 42, in _fileobject
fp.fileno = lambda: None
AttributeError: ’str’ object has no attribute ‘fileno’
INFO 2009-12-14 09:37:50,405 dev_appserver.py:3178] "GET / HTTP/1.1″ 500 -

有人愿意分享他们的工作机制 + appengine 代码吗?

Is anybody willing to share their working mechanize + appengine code?

推荐答案

这个问题我已经解决了,只是改了mechanize._http.py的代码,大约43行,来自:

I have solved this problem, just change the code of mechanize._http.py, about line 43,from:

try:
    socket._fileobject("fake socket", close=True)
except TypeError:
    # python <= 2.4
    create_readline_wrapper = socket._fileobject
else:
    def create_readline_wrapper(fh):
        return socket._fileobject(fh, close=True)

到:

try:
    # fixed start -- fixed for gae
    class x:
        pass

    # the x should be an object, not a string,
    # This is the key
    socket._fileobject(x, close=True)
    # fixed ended
except TypeError:
    # python <= 2.4
    create_readline_wrapper = socket._fileobject
else:
    def create_readline_wrapper(fh):
        return socket._fileobject(fh, close=True)

这篇关于Python 机械化 + GAEpython 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 03:51