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 -----
[EMAIL PROTECTED] 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, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Send twill mailing list submissions to
> [email protected]
>
> 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
> [EMAIL PROTECTED]
>
> You can reach the person managing the list at
> [EMAIL PROTECTED]
>
> 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 <[EMAIL PROTECTED]>
> Subject: Re: [twill] question about twill's functionality
> To: Xiangyi Meng <[EMAIL PROTECTED]>
> Cc: [email protected]
> Message-ID: <[EMAIL PROTECTED]>
> 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 <[EMAIL PROTECTED]>
> Subject: Re: [twill] question about twill's functionality
> To: Xiangyi Meng <[EMAIL PROTECTED]>
> Cc: [email protected], [EMAIL PROTECTED]
> Message-ID: <[EMAIL PROTECTED]>
> 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 <[EMAIL PROTECTED]>
> Subject: Re: [twill] question about twill's functionality
> To: [EMAIL PROTECTED]
> Cc: [email protected]
> Message-ID:
> <[EMAIL PROTECTED]>
> 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
> [email protected]
> http://lists.idyll.org/listinfo/twill
>
>
> End of twill Digest, Vol 15, Issue 11
> *************************************
>
_______________________________________________
twill mailing list
[email protected]
http://lists.idyll.org/listinfo/twill