A website has the following html elements:
<td class="right " data-stat="week_num">1</td>
<td class="right " data-stat="week_num">2</td>
<!-- etc -->
I was able to grab those elements with the following code:
import requests
from bs4 import BeautifulSoup
url = "https://www.pro-football-reference.com/players/H/HopkDe00.htm"
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
for item in soup.find_all(attrs={'data-stat':'week_num'}):
print(item)
This gets the requested html elements without an issue.
There is another set of elements I am trying to retrieve:
<tr id = 'stats.111' data-row='0'>
<tr id = 'stats.112' data-row='1'>
<!-- etc -->
To get these I figured I only had to alter the above code slightly. But this did not work. Note below that I tried passing 'True' as a string and just True, the program ran both times but no elements were printed to the console.
for item in soup.find_all(attrs={'data-row':True}): # attempted to get all elements with the `data-row` attribute, this returned `None`.
print(item)
I then attempted to just get a single element to test if I could do that with the same code.
for item in soup.find_all(attrs={'data-row':'1'}): # target just the <tr data-row='1'> element
print(item)
but this also returned nothing. How can I target this group of elements with the data-row attribute?