[twill] question about twill's functionality

Terry Peppers peppers at gmail.com
Wed Oct 25 07:23:16 PDT 2006


Xiangyi,

Re: Question 1. Syntax error. The traceback was this:

----- start traceback -----
File "postcost.py", line 10
    fv 1 origin_zip "211300"
       ^
SyntaxError: invalid syntax
----- end traceback -----

What you should do is this:

fv(1, "origin_zip", "211300")

You need to quote the field name - in this case "origin_zip" as well
as the value you're passing to the form "211300) and encase the fv
function in parentheses.

Re: Question 2. Extracting values from a form.

The way I've solved this problem is the following - I'll let Titus be
the judge of whether or not it's good practice or not:

---- start snippet -----
[terryp at Macintosh] learning :: python
Python 2.4.3 (#1, Apr  7 2006, 10:54:33)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from twill.commands import *
>>> from twill import get_browser
>>> u = "http://www.google.com"
>>> go(u)
==> at http://www.google.com
'http://www.google.com'
>>> fv(1, "q", "twill")
>>> form = get_browser().get_form("f")
>>> field = get_browser().get_form_field(form, "q")
>>> field.value
'twill'
>>>
---- end snippet -----

Some exposition is probably a good thing....

This snippet sends Twill to Google. It then fills in the Google search
box field (named 'q' by Google) to the value of 'twill'. It then asks
Twill to grab the form and grab the field and then ask for the field
attribute 'value' which is of course 'twill' since that's what we put
into the search field.

I hope that leads you down the right path.

t.

On 10/24/06, twill-request at lists.idyll.org
<twill-request at lists.idyll.org> wrote:
> Send twill mailing list submissions to
>         twill at lists.idyll.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://lists.idyll.org/listinfo/twill
> or, via email, send a message with subject or body 'help' to
>         twill-request at lists.idyll.org
>
> You can reach the person managing the list at
>         twill-owner at lists.idyll.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of twill digest..."
>
>
> Today's Topics:
>
>    1. Re:  question about twill's functionality (Titus Brown)
>    2. Re:  question about twill's functionality (Titus Brown)
>    3. Re:  question about twill's functionality (Xiangyi Meng)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 23 Oct 2006 13:38:32 -0700
> From: Titus Brown <titus at caltech.edu>
> Subject: Re: [twill] question about twill's functionality
> To: Xiangyi Meng <meng at are.Berkeley.EDU>
> Cc: twill at lists.idyll.org
> Message-ID: <20061023203832.GA29730 at caltech.edu>
> Content-Type: text/plain; charset=us-ascii
>
> On Mon, Oct 23, 2006 at 01:26:40PM -0700, Xiangyi Meng wrote:
> -> Dear Sir or Madam,
> ->
> -> I am wondering whether twill could recognize the authentication code on a
> -> web page. My research needs some shipment cost between any two counties in
> -> China. A company www.website-export.com provides this information: I just
> -> need to input counties' zip code, the web will return the cost to me. But
> -> each request needs an authentication code (numbers within an image) and I
> -> need to make about 12000
> -> requests to get the info I need. So I am wondering whether twill could
> -> help me with this. As long as I don't reflesh the web page (i.e., after
> -> one request, just click "back" button to make a new request), the
> -> authentication code won't change.
>
> Hi, Xiangyi,
>
> If the Web site is silly enough to let you make multiple requests with a
> single authentication code (are you *sure*??) then this should be easy
> to do.  All you'll have to do is enter the auth code manually once, and
> then use 'back' to go back to it.
>
> cheers,
> --titus
>
>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 23 Oct 2006 17:37:51 -0700
> From: Titus Brown <titus at caltech.edu>
> Subject: Re: [twill] question about twill's functionality
> To: Xiangyi Meng <meng at are.Berkeley.EDU>
> Cc: twill at lists.idyll.org, titus at idyll.org
> Message-ID: <20061024003751.GA22689 at caltech.edu>
> Content-Type: text/plain; charset=us-ascii
>
> -> Thanks a lot for your quick response! Twill is pretty cool.
>
> well, thanks ;)
>
> -> Two questions:
> -> 1.   File "postcost.py", line 10
> ->     fv 1 origin_zip "211300"
> ->        ^
> -> SyntaxError: invalid syntax
> ->
> -> Why do I get this error?
>
> Use twill-sh to run the file, instead of Python ;).
>
> In Python-speak, that would be
>
>         from twill.commands import *
>         fv('1', 'origin_zip', '211300')
>
> -> 2. how do I extract the field value from the web? For example, they have
> -> the field name for the authentication code as "vImageCode".
>
> I'm not sure what format it's in -- can I see the Web site, or (if not)
> can you run through what you would normally do with a Web browser
> and what you want to automate?
>
> cheers,
> --titus
>
>
>
> ------------------------------
>
> Message: 3
> Date: Mon, 23 Oct 2006 15:08:05 -0700 (PDT)
> From: Xiangyi Meng <meng at are.Berkeley.EDU>
> Subject: Re: [twill] question about twill's functionality
> To: titus at idyll.org
> Cc: twill at lists.idyll.org
> Message-ID:
>         <Pine.LNX.4.63.0610231505350.31183 at sneezy.ARE.Berkeley.EDU>
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
>
> Titus,
>
> Thanks a lot for your quick response! Twill is pretty cool.
>
> Two questions:
> 1.   File "postcost.py", line 10
>      fv 1 origin_zip "211300"
>         ^
> SyntaxError: invalid syntax
>
> Why do I get this error?
>
> 2. how do I extract the field value from the web? For example, they have
> the field name for the authentication code as "vImageCode".
>
> Thanks again for your time!
>
> Best,
> Xiangyi
>
> Xiangyi Meng
> University of California, Berkeley
> Agricultural & Resource Economics
> University of California, Berkeley
> Room 304, Giannini Hall
> Berkeley, CA 94720-3310
> Phone: 510-643-5419(O)
> Fax: 510-643-8911(F)
> Cell: 510-717-5785
>
> On Mon, 23 Oct 2006, Titus Brown wrote:
>
> > On Mon, Oct 23, 2006 at 01:26:40PM -0700, Xiangyi Meng wrote:
> > -> Dear Sir or Madam,
> > ->
> > -> I am wondering whether twill could recognize the authentication code on a
> > -> web page. My research needs some shipment cost between any two counties in
> > -> China. A company www.website-export.com provides this information: I just
> > -> need to input counties' zip code, the web will return the cost to me. But
> > -> each request needs an authentication code (numbers within an image) and I
> > -> need to make about 12000
> > -> requests to get the info I need. So I am wondering whether twill could
> > -> help me with this. As long as I don't reflesh the web page (i.e., after
> > -> one request, just click "back" button to make a new request), the
> > -> authentication code won't change.
> >
> > Hi, Xiangyi,
> >
> > If the Web site is silly enough to let you make multiple requests with a
> > single authentication code (are you *sure*??) then this should be easy
> > to do.  All you'll have to do is enter the auth code manually once, and
> > then use 'back' to go back to it.
> >
> > cheers,
> > --titus
> >
>
>
>
> ------------------------------
>
> _______________________________________________
> twill mailing list
> twill at lists.idyll.org
> http://lists.idyll.org/listinfo/twill
>
>
> End of twill Digest, Vol 15, Issue 11
> *************************************
>



More information about the twill mailing list