我对这个程序的想法是有一个简单的(假设)脚本来监控时间,当它在特定的时间范围内(例如早上6点到晚上7点)时,它会导航到opendns.com,并使用网页内容过滤功能阻止某些网站。
我想我应该从简单的开始,弄清楚登录网站和屏蔽网站的命令,然后担心时间的监控,等等。但不幸的是,我在这方面也有问题。
我正在使用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>发布于 2013-12-16 10:56:01
是的,python的斜纹内容并不是世界上最好的文档。我认为你基本上可以忘记"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()https://stackoverflow.com/questions/15047922
复制相似问题