計算機科学のブログ

ほしい物リスト

Python - Flask - gazpacho - Working with HTML - Web Scraping - Soup class, 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(コード、入出力結果)

WorldRecords.ipynb

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