mechanize の使い方を学ぶために、この小さなプロジェクトを作成することにしました。今のところ、urbandictionary に移動し、検索フォーム内に「skid」という単語を入力し、送信を押して HTML を出力します。
私がやりたいことは、最初の定義を見つけてそれを出力することです。どうすれば正確にそれを行うことができますか?
これはこれまでの私のソースコードです:
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()
定義が保存される場所は次のとおりです。
<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>
div 定義内に格納されていることがわかります。ソース コード内の div を検索する方法は知っていますが、タグの間にあるすべてのものを取得して表示する方法がわかりません。