GAE的机械化模块

时间:2011-05-28 09:30:39

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

我试图让机械化模块与GAE一起工作,但没有运气。 我使用了最新版本的mechanize和GAE特定的版本 Python Mechanize + GAEpython code

我想要做的是登录网站并提交表格。

示例代码

import mechanize

def mech(uname,passw,txtto,msg):
    br = mechanize.Browser()
    br.open("http://example.com")
    br.select_form(nr=0)

    br["username"]= uname
    br["password"]= passw
    # br.form

    response = br.submit()
    br.select_form(nr=0)
    # print br.form

    br["txt"] = txtto 
    br["message"] = msg

    br.submit()
    br.back()

使用机械化模块我

'str' object has no attribute 'fileno' 

和gaemechanize我得到

app.mechanize.ClientForm.ControlNotFoundError

ControlNotFoundError: no control matching name 'txt'

代码经过测试并在gae之外工作,所以这不是问题。 如果这有帮助,我正在使用kay框架。

1 个答案:

答案 0 :(得分:0)

看起来你正试图在Python GAE应用程序中执行此操作。非灵活环境GAE代码可以做什么限制(例如,限制炮轰其他进程等),这些限制在Google Cloud Functions中不存在。 我建议您从Google云端功能中尝试此操作。虽然GCF还没有正式的python支持,但有一个github project可以让你将python代码部署到GCF。 / p>

我能够使用Node.js chrome远程插件获得一些类似的浏览器自动化代码在GCF中工作,所以我认为GCF也适合你。

使用云功能也会占用大量的GAE应用程序,因此它是一个更好的解决方案,因为这实际上更多的是后台工作。

无论您决定使用Node.js还是Python来编写云功能,一旦设置完毕,您就可以从Python GAE应用程序中的Pub / Sub或HTTP触发器轻松调用它。

https://cloud.google.com/functions/