Python 对Twill使用showforms()命令时出现分析错误

Python 对Twill使用showforms()命令时出现分析错误,python,browser,web,navigation,twill,Python,Browser,Web,Navigation,Twill,我对这个程序的想法是有一个简单的(假定的)脚本来监控它的时间,当它在某个时间范围内(例如早上6点到晚上7点)时,它会导航到opendns.com并使用web内容过滤功能阻止某些网站 我想我应该简单地开始,然后找出登录网站和阻止网站的命令,然后再担心时间监控等问题。但遗憾的是,我在这方面也遇到了麻烦 我正在使用,但不确定这是否是个好主意。这是除了mechanize之外我能找到的唯一一个(我找不到合适的文档,但也许我只是找不到合适的地方) 这是我的代码(好吧,它还不是真正的代码。只是Python S

我对这个程序的想法是有一个简单的(假定的)脚本来监控它的时间,当它在某个时间范围内(例如早上6点到晚上7点)时,它会导航到opendns.com并使用web内容过滤功能阻止某些网站

我想我应该简单地开始,然后找出登录网站和阻止网站的命令,然后再担心时间监控等问题。但遗憾的是,我在这方面也遇到了麻烦

我正在使用,但不确定这是否是个好主意。这是除了mechanize之外我能找到的唯一一个(我找不到合适的文档,但也许我只是找不到合适的地方)

这是我的代码(好吧,它还不是真正的代码。只是Python Shell的命令列表):

这就是我的问题开始的地方。 在最后一个b.showforms()中,我得到一个错误:

Traceback (most recent call last):
  File "<pyshell#43>", line 1, in <module>
    b.showforms()
  File "C:\Python27\lib\site-packages\twill-0.9-py2.7.egg\twill\browser.py", line 225, in showforms
    forms = self.get_all_forms()
  File "C:\Python27\lib\site-packages\twill-0.9-py2.7.egg\twill\browser.py", line 259, in get_all_forms
    global_form = self._browser.global_form()
  File "C:\Python27\lib\site-packages\twill-0.9-py2.7.egg\twill\other_packages\_mechanize_dist\_mechanize.py", line 446, in global_form
    return self._factory.global_form
  File "C:\Python27\lib\site-packages\twill-0.9-py2.7.egg\twill\utils.py", line 334, in get_global_form
    return self.factory.global_form
  File "C:\Python27\lib\site-packages\twill-0.9-py2.7.egg\twill\other_packages\_mechanize_dist\_html.py", line 521, in __getattr__
    self.forms()
  File "C:\Python27\lib\site-packages\twill-0.9-py2.7.egg\twill\other_packages\_mechanize_dist\_html.py", line 534, in forms
    self._forms_factory.forms())
  File "C:\Python27\lib\site-packages\twill-0.9-py2.7.egg\twill\other_packages\_mechanize_dist\_html.py", line 226, in forms
    raise ParseError(exc)
ParseError: <unprintable ParseError object>
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
b、 showforms()
文件“C:\Python27\lib\site packages\twill-0.9-py2.7.egg\twill\browser.py”,第225行,在showforms中
forms=self.get_all_forms()
文件“C:\Python27\lib\site packages\twill-0.9-py2.7.egg\twill\browser.py”,第259行,格式为get\U all\U
global\u form=self.\u browser.global\u form()
文件“C:\Python27\lib\site packages\twill-0.9-py2.7.egg\twill\other\u packages\\u mechanize\u dist\\u mechanize.py”,第446行,全局形式
返回自我工厂。全局表单
文件“C:\Python27\lib\site packages\twill-0.9-py2.7.egg\twill\utils.py”,第334行,格式为get\u global\u
返回self.factory.global\u表单
文件“C:\Python27\lib\site packages\twill-0.9-py2.7.egg\twill\other\u packages\\u mechanize\u dist\\u html.py”,第521行,位于__
self.forms()
文件“C:\Python27\lib\site packages\twill-0.9-py2.7.egg\twill\other\u packages\\u mechanize\u dist\\u html.py”,第534行,格式为
self.\u forms\u factory.forms())
文件“C:\Python27\lib\site packages\twill-0.9-py2.7.egg\twill\other\u packages\\u mechanize\u dist\\u html.py”,第226行,格式为
提升解析错误(exc)
解析错误:

是的,python的twill文档并不是世界上最好的文档。我想你基本上可以忘记“获取浏览器”的东西。斜纹织物对我来说更清晰一些:

import twill.commands as twill

username = "username@email.com" # email for opendns
password = "thisisthepassword" # password for opendns

twill.go("https://dashboard.opendns.com/")
twill.showforms()

twill.fv("2", "username", username)
twill.fv("2", "password", password)
twill.showforms()

twill.submit("sign-in")

twill.showforms()

twill.go ("https://dashboard.opendns.com/settings/*MYNETWORKID*/content_filtering") # I replaced my network ID due to privacy reasons but this is basically the URL to the web content filtering page on OpenDNS for a network

twill.showforms()
import twill.commands as twill

username = "username@email.com" # email for opendns
password = "thisisthepassword" # password for opendns

twill.go("https://dashboard.opendns.com/")
twill.showforms()

twill.fv("2", "username", username)
twill.fv("2", "password", password)
twill.showforms()

twill.submit("sign-in")

twill.showforms()

twill.go ("https://dashboard.opendns.com/settings/*MYNETWORKID*/content_filtering") # I replaced my network ID due to privacy reasons but this is basically the URL to the web content filtering page on OpenDNS for a network

twill.showforms()