計算機科学のブログ

ほしい物リスト

Python - gazpacho - Working with HTML: Web Scraping - html,tkable, row, colums

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)、EXERCISE(445/682)の解答を求めてみる。

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

webapp/WorldRecords.ipynb

table = tables[0]
for tr in table.find('tr', mode='all')[1:]:
    colums = tr.find('td', mode='all')
    event = colums[0].text
    text = colums[1].text
    print(f'{event} {text}')
50m freestyle 20.91
100m freestyle 46.40
200m freestyle 1:42.00
400m freestyle 3:40.07
400m freestyle 3:39.96
800m freestyle 7:32.12
1500m freestyle 14:30.67
50m backstroke 23.55
100m backstroke 51.60
200m backstroke 1:51.92
50m breaststroke 25.95
100m breaststroke 56.88
200m breaststroke 2:05.48
50m butterfly 22.27
100m butterfly 49.45
200m butterfly 1:50.34
200m individual medley 1:54.00
400m individual medley 4:02.50
4 × 100 m freestyle relay 3:08.24
4 × 200 m freestyle relay 6:58.55
4 × 100 m medley relay 3:26.78