这允许我在我的计算机上使用 python 连接到一个网站:
from twill.commands import go, show, showforms, formclear, fv, submit
from bs4 import BeautifulSoup as bs
go('http://www.pge.com')
showforms()
这让我在谷歌应用引擎上打招呼,斜纹和美丽的汤导入工作:
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)
现在在此之后我尝试使用斜纹连接到一个网站并失败:
我在哪里可以调用 go() 连接到网站?
如果我在class MainPage(webapp2.RequestHandler):它挂起之前添加它并且我没有进入你好世界。
如果我将它添加到第一行的 MainPage 类中getit = go('http://www.pge.com'),或者只是go('http://www.pge.com'),它也会挂起,我不会进入 hello world。
如果我在里面添加它def: get(self):,我会得到:
内部服务器错误
服务器出错或无法执行请求的操作。还有一堆关于twill和mechanize.py的东西,然后是
File "..../twill/utils.py", line 275, in run_tidy
process = subprocess.Popen(_tidy_cmd, stdin=subprocess.PIPE,
AttributeError: 'module' object has no attribute 'Popen'
我是否以某种方式缺少其他一些依赖项,例如 mechanize.py?还是我需要做其他事情?