【问题标题】:Parse Error when using showforms() command with Twill使用带有斜纹的 showforms() 命令时出现解析错误
【发布时间】:2013-02-09 11:20:10
【问题描述】:

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

我想我会从简单的开始,只需弄清楚登录网站和阻止网站的命令,然后担心时间监控等。但遗憾的是,我也遇到了麻烦。

我正在使用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>

【问题讨论】:

    标签: python browser web navigation twill


    【解决方案1】:

    是的,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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-01
      • 2012-08-08
      • 1970-01-01
      • 2014-06-28
      • 2021-09-08
      • 1970-01-01
      • 2016-12-08
      相关资源
      最近更新 更多