計算機科学のブログ

ほしい物リスト

Python - Working with HTML: Web Scraping - gazpacho, Soup, find method

Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly GuidePaul Barry(著)、 O’Reilly Mediaの Chapter 9.(Working with HTML: Web Scraping)、SHARPEN YOUR PENCIL(439/682)の解答を求めてみる。

Jupyter(コード、入出力結果)

webapp/WorldRecords.ipynb

soup = gazpacho.Soup(html)
table: gazpacho.soup.Soup
for i, table in enumerate(soup.find('table', mode='all')):
    rows = table.find('tr', mode='all')
    print(f'{i}: {len(rows)}')
0: 22
1: 1
2: 21
3: 3
4: 25
5: 26
6: 4
7: 26
8: 1
9: 7
10: 5
11: 8