Sending information to a website

Jeff McNeil jeff at jmcneil.net
Tue Jun 24 10:37:12 EDT 2008


On Jun 24, 12:13 am, Alex Bryan <alexnbr... at gmail.com> wrote:
> Okay, so what I want to do is connect to dictionary.com and send the
> website a word, and later receive the definition. But for now, I want
> to focus on sending the word. A good guy from this mailing list said I
> should look into the code and then figure out what the word you want
> to be defined is called by the website. In other words, what is the
> name of the word the user inputs. Okay, so using the firebug extension
> I got the code that the search field on the website uses. here is that
> code.
>
> <div id="search">
>         <form onsubmit="return formcheck();" action="/search" method="get"
> name="search_form">
>                 <input id="search-terms" class="text" type="text" maxlength="256"
> value="" name="q"/>
>
> Anyway, not to get to complicated. How would any of you suggest I send
> this word to the site. While bearing in mind that I will need to
> return it if it matters for this step.

You should be able to automate the submission via urllib.urlopen.  On
success, that call will return a file-like object that contains the
response HTML code. You do need to be a bit careful when 'screen
scraping' as many sites have terms of service agreements that
explicitly deny automating requests.

Once you've got the HTML back, you'll need to pull the definition out.
Look at BeautifulSoup.



More information about the Python-list mailing list