activating a webpage's click command from python

Christopher Browne cbbrowne at
Mon Jun 10 20:38:30 CEST 2002

In an attempt to throw the authorities off his trail, Peter Hansen <peter at> transmitted:
> "Grimes, Jessica C" wrote:
>> I want to create a  program that will ask the user what stock he/she 
>> wants to look up.  The program will then extract financial data from 
>> yahoo and import it into a spreadsheet.
>> My problem is that I don't know how to make the application take the 
>> user's input (the stock's ticker symbol) and place the user's input 
>> from python into the space where yahoo accepts input for a ticker 
>> symbol and activate yahoo's "Look up" click command.
> You should investigate HTML forms.  The web page contains a form
> which has several fields and a target URL.  If you view the source
> for the page (in Netscape, hit Ctrl-U; in IE use the View->Source
> menu) you can find buried within it the form and the names of the
> fields.  Forms use the <form> tag and contain <input> fields.
> Looking at I can see the form calls "/q" when
> executed, and has a field named "s" for the stock symbol.  You
> can easily take such forms and compose a URL which retrieves the
> data.  In this case this:
> does the job for Nortel on the TSE (disclaimer: anyone even 
> thinking of buying Nortel should probably just keep thinking :-).
> The page returned contains the data, but it's embedded deep
> in the HTML and you _really_ don't want to waste much of your
> time trying to figure this out.  There's got to be a better 
> approach, but I have never spent the time to research it.

The SOAPy way would be:

#!/usr/bin/env python
import SOAP
from SOAP import *
server = ""
namespace= "urn:xmethods-delayed-quotes"
serv = SOAP.SOAPProxy(server, namespace=namespace)
stocks = ["LNUX", "NT", "TSG", "RHAT", "IBM", "MSFT", "AMR"]
print "Stock    Price"
print "================"
for el in stocks:
    print "%6s %8.3f" % (el, serv.getQuote(symbol=el))
(reverse (concatenate 'string "moc.enworbbc@" "sirhc"))
"war is an inappropriate analogy; ``flame war'' is a misnomer.
 in any usenet exchange, the only casualty is time.
 there are better uses for regret."
    --thi <ttn at>

More information about the Python-list mailing list