[英]Python Mechanize + GAEpython code
I am aware of previous questions regarding mechanize + Google App Engine, What pure Python library should I use to scrape a website? 我知道有关机械化+ Google App Engine的先前问题, 我应该使用什么纯Python库来抓取网站? and Mechanize and Google App Engine .
和Mechanize和Google App Engine 。
Also there is some code here , which I cannot get to work on app engine, throwing 也有一些代码在这里 ,我不能让在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 -
Is anybody willing to share their working mechanize + appengine code? 有人愿意分享他们的工作机械化和附加代码吗?
I have solved this problem, just change the code of mechanize._http.py, about line 43, from: 我已经解决了这个问题,只需更改第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)
to: 至:
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)
I managed to get mechanize code that runs on GAE, many thanks to MStodd, from GAEMechanize project http://code.google.com/p/gaemechanize/ and 我设法获得了在GAE上运行的机械化代码,非常感谢MStodd,来自GAEMechanize项目http://code.google.com/p/gaemechanize/和
If anybody needs the code, you can contact MStodd ! 如果有人需要代码,您可以联系MStodd!
ps: the code is not on google code, so you have to contact the owner.. ps:代码不在谷歌代码上,所以你必须联系所有者..
Cheers don 欢呼声
I've uploaded the source of the gaemechanize project to a new project: http://code.google.com/p/gaemechanize2/ 我已将gaemechanize项目的来源上传到一个新项目: http : //code.google.com/p/gaemechanize2/
Insert usual caveats. 插入通常的警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.