KOTA ITO

Generation

generate functionFri, 16 Dec 2022

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

def get_rank(url, tag, attribute, attribute_name, index_start, index_end): html = urllib.request.urlopen(url).read() soup = BeautifulSoup(html, "html.parser") rank = [] for i in range(index_start, index_end): element = soup.select(tag)[i] rank.append(element[attribute]) return rank rank = get_rank(url, 'tr', 'class', '', 22, 27)

Questions about programming?Chat with your personal AI assistant