計算機科学のブログ

ほしい物リスト

Python - Flask - gazpacho - Working with HTML - Web Scraping - for loop

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(コード、入出力結果)

WorldRecords.ipynb

for row in table.find('tr', mode='all')[1:]:
    columns = row.find('td', mode='all')
    event = columns[0].text
    time = columns[1].text
    print(f'{event}, {time}')
50m freestyle, 20.91
100m freestyle, 46.40
200m freestyle, 1:42.00
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:52.69
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