Python - gazpacho - Working with HTML: Web Scraping - table, columns, td
Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly Guide、 Paul Barry(著)、 O’Reilly Mediaの Chapter 9.(Working with HTML: Web Scraping)、EXERCISE(441/682)の解答を求めてみる。
Jupyter(コード、入出力結果)
webapp/WorldRecords.ipynb
for i, table in enumerate(tables, start=1):
rows = table.find('tr', mode='all')
cols = rows[-1].find('td', mode='all')
print(f'{i} {len(rows)} rows, {len(cols)} cols')
1 21 rows, 9 cols
2 21 rows, 9 cols
3 3 rows, 9 cols
4 26 rows, 9 cols
5 28 rows, 9 cols
6 4 rows, 9 cols
7 25 rows, 11 cols
8 1 rows, 2 cols
9 7 rows, 1 cols
10 5 rows, 1 cols
11 8 rows, 1 cols