私は現在 Scrapers のコードを書いており、ますます Python、特に BeautifulSoup のファンになっています。
それでも... htmlを解析していると、あまり美しくない方法でしか使えない難しい部分に出くわしました。
HTMLコード、特に次のスニペットをスクレイピングしたい:
<div class="title-box">
<h2>
<span class="result-desc">
Search results <strong>1</strong>-<strong>10</strong> out of <strong>10,009</strong> about <strong>paul mccartney</strong><a href="alert/settings" class="title-email-alert-promo x-title-alerts-promo">Create email Alert</a>
</span>
</h2>
</div>
だから私がすることは、次を使用して div を識別することです。
comment = TopsySoup.find('div', attrs={'class' : 'title-box'})
次に、醜い部分が入ります。必要な数をキャッチするには、10,009 を使用します。
catcher = comment.strong.next.next.next.next.next.next.next
もっと良い方法があれば誰か教えてもらえますか?