Python Mechanize + GAEpython代码

Don*_* Ch 5 python google-app-engine mechanize-python

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

也有一些代码在这里,我不能让在App Engine上工作,抛

File “D:\data\eclipse-php\testpy4\src\mechanize\_http.py”, line 43, in socket._fileobject(”fake socket”, close=True)
File “C:\Program Files (x86)\Google\google_appengine\google\appengine\dist\socket.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 -
Run Code Online (Sandbox Code Playgroud)

有人愿意分享他们的工作机械化和附加代码吗?

Mic*_*ael 10

我已经解决了这个问题,只需更改第43行的mechanize._http.py的代码:

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)
Run Code Online (Sandbox Code Playgroud)

至:

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)
Run Code Online (Sandbox Code Playgroud)

  • 这目前需要进入_urllib2_fork.py (10认同)

Don*_* Ch 1

我设法从 GAEMechanize 项目http://code.google.com/p/gaemechanize/获得在 GAE 上运行的机械化代码,非常感谢MStodd

如果有人需要代码,可以联系 MStodd !

ps:该代码不在谷歌代码上,因此您必须联系所有者。

干杯,唐