【问题标题】:Python Mechanize + GAEpython codePython Mechanize + GAEpython 代码
【发布时间】:2012-07-30 01:39:38
【问题描述】:

我知道之前有关 mechanize + Google App Engine 的问题, What pure Python library should I use to scrape a website?Mechanize and Google App Engine

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

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 -

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

【问题讨论】:

    标签: python google-app-engine mechanize-python


    【解决方案1】:

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

    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)
    

    【讨论】:

    • 这个目前需要进入_urllib2_fork.py
    • 如果您现在(2011 年 12 月)尝试这样做,它不在同一个文件中,而是在 urllib2 中
    【解决方案2】:

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

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

    ps:代码不在google code上,所以你必须联系所有者..

    干杯 不要

    【讨论】:

      【解决方案3】:

      我已将 gaemechanize 项目的源代码上传到一个新项目:http://code.google.com/p/gaemechanize2/

      插入通常的警告。

      【讨论】:

        猜你喜欢
        • 2017-01-05
        • 2016-12-14
        • 2022-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多