How to enter the site using the installed twill?

I just successfully installed TWILL on my computer with one very supportive member of StackOverflow (you can check it HERE ) and try to run one of the simple examples on the Twill documentation page (you can see this page HERE ) Here is this example:

alt text
(source: narod.ru )

Suppose my username at www.slash.org is lynxye and my password is mammal . When I try to enter this sample code into the Python prompt, I can only enter and enter the first line of code, because when I press "Enter" to start a new line, I immediately get error messages:

alt text
(source: narod.ru )

The same thing happens when I try to enter this code into my terminal:

alt text
(source: narod.ru )

I think I'm missing some basics here. Maybe I need to create a file that will contain this code, and then somehow run this file, but I really don't know where I need to create this file and with what extension.

Can someone please help me with this?

+6
python logging twill
source share
4 answers

You need to run these commands inside the twill shell, instead of the python shell

D:\tmp\twill-0.9> python twill-sh -= Welcome to twill! =- current page: *empty page* >> 

You can set twill commands when you see >>

or there are only two lines in the twill-sh file

 import twill.shell twill.shell.main() 

you can just copy the insert that 2 lines in the python command line.

 >>> import twill.shell >>> twill.shell.main() -= Welcome to twill! =- current page: *empty page* >> ? Undocumented commands: ====================== add_auth fa info save_html title add_extra_header find load_cookies setglobal url agent follow notfind setlocal back formaction redirect_error show clear_cookies formclear redirect_output show_cookies clear_extra_headers formfile reload show_extra_headers code formvalue reset_browser showforms config fv reset_error showhistory debug get_browser reset_output showlinks echo getinput run sleep exit getpassword runfile submit extend_with go save_cookies tidy_ok current page: *empty page* >> 
+4
source share

This will do the following:

 >>> import twill.commands >>> import re >>> >>> class browser: ... def __init__(self, url="http://www.slashdot.org"): ... self.a=twill.commands ... self.a.config("readonly_controls_writeable", 1) ... self.b = self.a.get_browser() ... self.b.set_agent_string("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") ... self.b.clear_cookies() ... self.url=url ... def slashdot(self, loginName, passwd): ... self.b.go(self.url) ... f = self.b.get_form("1") ... regexp = re.compile("Log In") ... link = self.b.find_link(regexp) ... if link: ... self.b.follow_link(link) ... f=self.b.get_form("2") ... f["unickname"] = loginName ... f["upasswd"] = passwd ... self.a.fv("2", "userlogin", "") ... >>> >>> t=browser() >>> t.slashdot("username", "password") ==> at http://slashdot.org/ ==> at http://slashdot.org/my/login forcing read-only form field to writeable >>> 

Its also easier if you use BeautifulSoup for html analysis

+3
source share

Angle brackets should not be entered literally; they simply indicate that you must enter a value. Try

setlocal username lynxye

instead.

0
source share

This is not a hint to use.

You need to enclose the key-value pair in parentheses. How,

SETLOCAL ('uname', 'XYZ')

SETLOCAL ('password', '123')

go (' http://abc.org ')

bs ('1', 'Foo', 'bar')

0
source share

All Articles