I decided to make this little project to learn how to use mechanize. For now it goes to urbandictionary, fills in the word 'skid' inside the search form and then press submit and prints out the HTML.
What I want it to do is to find the first definition and print that out. How would I exactly go and do that?
This is my source code so far:
import mechanize
br = mechanize.Browser()
page = br.open("http://www.urbandictionary.com/")
br.select_form(nr=0)
br["term"] = "skid"
br.submit()
print br.response().read()
Here's where the definition is stored:
<div class="definition">Canadian definition: Commonly used to refer to someone who stopped evolving, and bathing, during the 80's hair band era. Generally can be found wearing AC/DC muscle shirts, leather jackets, and sporting a <a href="/define.php?term=mullet">mullet</a>. The term "skid" is in part derived from "skid row", which is both a band enjoyed by those the term refers to, as well as their address. See also <a href="/define.php?term=white%20trash">white trash</a> and <a href="/define.php?term=trailer%20park%20trash">trailer park trash</a></div><div class="example">The skid next door got drunk and beat up his old lady.</div>
You can see it's stored inside the div definition. I know how to search for the div inside the source code but I don't know how to take everything that's between the tags and then display it.