我对这个程序的想法是有一个简单的(假设是)脚本来监控现在是什么时间,当它在某个时间范围内(例如早上 6 点到晚上 7 点)时,它会导航到 opendns.com 并阻止某些网站使用 web 内容过滤功能。
我以为我会从简单的开始,只需找出登录网站和阻止网站的命令,然后担心时间监控等。但可悲的是,我也遇到了麻烦。
我正在使用http://twill.idyll.org/但不确定这是否是个好主意。这是除了 mechanize 之外我能找到的唯一一个(我找不到正确的文档,但也许我只是没有在正确的地方寻找)
这是我的代码(嗯,它还不是真正的代码。只是 Python Shell 的命令列表):
from twill import get_browser
from twill.commands import *
username = "username@email.com" # email for opendns
password = "thisisthepassword" # password for opendns
b = get_browser()
b.go("https://dashboard.opendns.com/")
b.showforms()
fv("2", "username", username)
fv("2", "password", password)
showforms()
submit("sign-in")
b.showforms()
b.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
b.showforms()
现在这就是我的问题开始的地方。在最后一个 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>