計算機科学のブログ

ほしい物リスト

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

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

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