这使我可以连接到计算机上带有python的网站:
from twill.commands import go, show, showforms, formclear, fv, submit
from bs4 import BeautifulSoup as bs
go('http://www.pge.com')
showforms()
这让我在google app engine上看到了hello world,斜纹和漂亮的汤导入工作正常:
import webapp2
import sys
sys.path.insert(0, 'libs')
from twill.commands import go, show, showforms, formclear, fv, submit
from bs4 import BeautifulSoup as bs
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Hello, World! I love dog food.')
application = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
在此之后,我尝试使用twill连接到一个网站,但失败了:
在哪里可以调用go()连接到网站?你知道吗
如果我在class MainPage(webapp2.RequestHandler):
之前加上它,它就会挂起,我就不能进入hello world了。你知道吗
如果我在MainPage类的第一行将它添加为getit = go('http://www.pge.com')
,或者仅仅是go('http://www.pge.com')
,它也会挂起,我无法访问helloworld。你知道吗
如果我把它加到def: get(self):
里面,我会得到:
Internal Server Error
The server has either erred or is incapable of performing the requested operation. and a bunch of stuff about twill and mechanize.py, followed by
File "..../twill/utils.py", line 275, in run_tidy
process = subprocess.Popen(_tidy_cmd, stdin=subprocess.PIPE,
AttributeError: 'module' object has no attribute 'Popen'
我是不是错过了一些其他的依赖,比如机械化.py?或者我还有别的事要做?你知道吗
这有助于部分解决我的问题,但其他问题后来突然出现,特别是在填写表格,提交他们,并在网站上进一步迁移。你知道吗
tidy是以这种方式禁用的(tidy不能很好地使用google沙盒),我可以通过
self.response.write(show())
显示()网页。你知道吗另请注意:在使用googleappengine时,要小心使用TextEdit来编辑.py文件。我收到了各种奇怪的非ascii字符错误。我在python文件的第一行添加了#--编码:utf-8--这有点帮助,然后改用pycharm的ide,这确实有帮助。你知道吗
twill在googleappengine的沙盒中给了我各种各样的问题,而我的系统上没有这些问题。我终于可以得到一个网页的html,但不能提交表单的方式,我这样做只是在我的系统。showforms()甚至没有显示表单,可能是因为我禁用了tidy,而html没有被正确解析?你知道吗
我认为一个前进的方法就是在斜纹布里面整理工作。很明显,路障正在被“引擎盖下”击中,我很难看到它们。你知道吗
twill似乎是一个高级抽象,现在在googleappengine上使用可能不是一个好主意。下一步我将尝试切换到机械化.py,或者寻找另一个沙盒,也许亚马逊?你知道吗
相关问题 更多 >
编程相关推荐