我对这个程序的想法是有一个简单的(据说)脚本来监视它的时间,以及它在某个时间范围内(例如早上6点到晚上7点)它导航到opendns.com并阻止使用某些网站网络内容过滤功能。
现在因为我是python的新手我觉得我开始很简单,只是弄清楚登录网站和阻止网站的命令,并担心稍后监控时间等。但遗憾的是我也遇到了麻烦。
我正在使用http://twill.idyll.org/,但不确定这是不是一个好主意。除了机械化之外,这是我唯一能找到的(我找不到合适的文档,但也许我只是找不到合适的地方)
这是我的代码(好吧,它还不是真正的代码。只是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>
有人可以帮助我或指出我正确的方向吗? 如果您认为我完全错了,请告诉我,即使您认为我应该使用其他语言。就像我说这是我的第一个程序,所以我并不过分依赖Python,我只是被告知这对于这样的程序是完美的。
抱歉,如果我以错误的格式发布此问题或其他内容。我尽力遵守指南,如果有什么我需要更改或需要提供的更多信息,请告诉我。
提前感谢任何花时间帮助我的人,我知道这对大多数人来说似乎是一个明显回答的问题。
答案 0 :(得分:0)
是的,python的twill东西不是世界上最好的文档。我认为你基本上可以忘记“get_browser”的东西。斜纹布的东西对我来说有点清晰:
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()