[英]Python Mechanize + GAEpython code
我知道有關機械化+ 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 -
有人願意分享他們的工作機械化和附加代碼嗎?
我已經解決了這個問題,只需更改第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)
至:
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)
我設法獲得了在GAE上運行的機械化代碼,非常感謝MStodd,來自GAEMechanize項目http://code.google.com/p/gaemechanize/和
如果有人需要代碼,您可以聯系MStodd!
ps:代碼不在谷歌代碼上,所以你必須聯系所有者..
歡呼聲
我已將gaemechanize項目的來源上傳到一個新項目: http : //code.google.com/p/gaemechanize2/
插入通常的警告。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.