KOTA ITO

Generation

generate functionFri, 16 Dec 2022

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

BASE_URL = 'https://www.credit-suisse.com/jp/ja/investment-services/research/regional-strategy/' def get_table_data(url, xpath): import requests from bs4 import BeautifulSoup source = requests.get(url) soup = BeautifulSoup(source.content, 'lxml') print(soup.select_one(xpath).get_text()) get_table_data(BASE_URL, '//*[@id="rankingChart"]/tbody/tr[22]/td')

Questions about programming?Chat with your personal AI assistant