KOTA ITO

Generation

generate functionFri, 16 Dec 2022

beaurifulsoupを使って、WEBサイトの中の、 X-path '//*[@id="rankingChart"]/tbody/tr[22]/td' の中にある文字列をすべて取得する

import requests from bs4 import BeautifulSoup url = 'http://www.mhlw.go.jp/toukei/saikin/hw/kansen/kansen_h25_1.html' html = requests.get(url).text soup = BeautifulSoup(html, 'html.parser') for tag in soup.find_all('tr'): if tag.has_attr('class'): print(tag.text)

Questions about programming?Chat with your personal AI assistant