在Python中抓取网页时表格不出现

问题描述 投票:0回答:0

我发生了一件有趣的事情,但我不知道发生了什么。我正在尝试从以下位置进行网络抓取:

https://www.pro-football-reference.com/teams/kan/2023_roster.htm

我想要拉的表是“Roster”表。理论上我应该能够使用 pd.read_html(link, match = 'Roster') 但是当我这样做时它不会显示任何结果。事实上,当我只执行 pd.read_html 时,返回的是预期列表,但只有一张表。我进入 HTML 并确认该表存在,因此我决定尝试使用 BS。


table = soup.find_all("div", id = 'all_roster' )
table[0]

部分输出::

[<div class="table_wrapper setup_long long setup_commented commented" id="all_roster">
 <div class="section_heading assoc_roster" id="roster_sh">
 <span class="section_anchor" data-label="Roster" id="roster_link"></span><h2>Roster</h2> <div class="section_heading_text">
 <ul><li>*ProBowl, +<a href="/about/allpro.htm">1st-tm All-Pro</a></li>
 </ul>
 </div>
 </div><div class="placeholder"></div>
 <!--
 
 <div class="table_container" id="div_roster">
     
     <table class="per_match_toggle sortable stats_table" id="roster" data-cols-to-freeze=",2">
     <caption>Roster Table</caption>
     
 
    <colgroup><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup>
    <thead>      
       <tr>
          <th aria-label="No." data-stat="uniform_number" scope="col" class=" poptip sort_default_asc center" data-tip="Uniform number" >No.</th>
          <th aria-label="Player" data-stat="player" scope="col" class=" poptip sort_default_asc show_partial_when_sorting left" >Player</th>
          <th aria-label="Age" data-stat="age" scope="col" class=" poptip sort_default_asc center" data-tip="Player's age on December 31st of that year" >Age</th>

正如你所看到的,该表存在......但我一生都无法获得漂亮的汤或 read_html 来找到该表。就像“

python pandas web-scraping beautifulsoup
© www.soinside.com 2019 - 2024. All rights reserved.