Pythonのスクレイピングで、テキストが取得できない項目がある

実現したいこと

ウェブページから、会場名入場者数を取得したいです。

前提

会場名は問題なく取得できるのですが、入場者数が取得できません。
HTML構造を見ても、なぜ会場は取得できて人数が取得できないのかが分からないので教えていただけないでしょうか?

該当のソースコード

python

1# インポート2import requests 3from bs4 import BeautifulSoup 4 5# 練習として、1つのurlを指定6url_test = 'https://www.bleague.jp/game_detail/?ScheduleKey=501556&tab=2'7 8# ページの情報を取得9url_detail = requests.get(url_test)10 11# urlと、パーサー(解析器)を指定12soup = BeautifulSoup(url_detail.text, 'html.parser')13 14# 試合情報が記載されている箇所を取得15detail = soup.find('section', class_="game-top")16 17# 試合情報が含まれる箇所を指定18venue = detail.find('span', class_="link-line").text 19attendance = detail.find('span', class_="attendance")20 21print(venue)22print(attendance)

該当箇所のHTML構造

<div class="inner">   <span class="stadium-name">     "会場:"     <a href="https://www.bleague.jp/arena_detail/?ArenaCD=47" class="text-link-white link-white"><span class="link-line">北海きたえーる</span></a></span>   <span class="attendance">人数:4535人</span>   <span class="referee">レフェリー:審判名</span> </div>

補足情報(FW/ツールのバージョンなど)

python 3.12.0

コメントを投稿

0 コメント