2013-02-24 58 views
1

解析錯誤與我裸這一點,因爲它是我的第一個Python程序。我花了幾個小時搜索和測試一個解決方案,但我在那個地方,我認爲我只需要一個好心人的幫助。使用showforms()命令與斜紋

我對這個程序的想法是有一個簡單的(應該是)腳本來監視它是什麼時間,當它在一定的時間範圍內(例如上午6點到下午7點),它導航到opendns.com並阻止某些網站使用網頁內容過濾功能。

現在因爲我是新手,當談到python時,我想我會簡單地開始它,只是找出命令來登錄到網站和阻止一個網站,並擔心後來的監控時間等上。但遺憾的是,我也遇到了麻煩。我正在使用http://twill.idyll.org/,但不確定這是不是一個好主意。這是我除了機械化之外唯一可以找到的(我找不到合適的文檔,但也許我只是沒有找到正確的位置)

這是我的代碼(好吧,它不是真的代碼但是,只是Python Shell命令列表):

from twill import get_browser 
from twill.commands import * 

username = "[email protected]" # 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

是的,Python的斜紋東西不是世界上最好的文檔。我想你基本上可以忘掉「get_browser」的東西。斜紋布對我來說有點清晰:

import twill.commands as twill 

username = "[email protected]" # 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()