I am doing some data mining on football stats using Python's BeautifulSoup. There are some tables that give issues when trying to filter through the soup. Upon further inspection it looks like the data I need is contained within a comment, which is not the case when looking at it through the web developer tools.
import requests
from bs4 import BeautifulSoup, Comment
url='https://aws.pro-football-reference.com/teams/mia/2000.htm'
page = requests(url)
soup = BeautifulSoup(page, 'html.parser')
table = soup.find(id='all_passing')
print(table)
Below is a sample of what is printed.
<div class="table" id="all_passing"> <div class="placeholder"></div> <!-- <div class="table_outer_container">
<div class="overthrow table_container" id="div_passing">
<table class="sortable stats_table" id="passing" <caption>Passing Table</caption> <colgroup><col><col><col></colgroup> <thead>
<tr>
<th aria-label="Uniform number" data-stat="uniform_number" scope="col">No.</th>
<th aria-label="Player's age" data-stat="age" scope="col">Age</th> <th aria-label="Position" data-stat="pos" scope="col">Pos</th>
</tr>
</thead> <tbody> <tr ><th scope="row" class="right " data-stat="uniform_number" >9</th><td class="right " data-stat="age"
>29</td><td class="left " data-stat="pos" >QB</td></tr> </tbody> </table>
</div> </div>
--> <div class="placeholder"></div> </div>
How do I go about filtering down the comments? This is what I have tried.
comments = table.find_all(text=lambda text:isinstance(text, Comment))
rows = comments[0].find_all('tr')
print('rows: ' + rows)
This prints:
None