[twill] question about twill's functionality
titus at caltech.edu
Wed Oct 25 09:25:25 PDT 2006
On Wed, Oct 25, 2006 at 09:23:16AM -0500, Terry Peppers wrote:
-> 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:
[ ... ]
looks good to me! I ended up suggesting BeautifulSoup to Xiangyi, which
worked better for extracting HTML table locations directly. But the
code you sent out (below) is great for getting specific field values.
-> >>> from twill.commands import *
-> >>> from twill import get_browser
-> >>> u = "http://www.google.com"
-> >>> go(u)
-> ==> at http://www.google.com
-> >>> fv(1, "q", "twill")
-> >>> form = get_browser().get_form("f")
-> >>> field = get_browser().get_form_field(form, "q")
-> >>> field.value
-> ---- 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.
More information about the twill