I can’t get the code to find the text found in the race form table, highlighted in the element below. What are the appropriate elements to actually getting that text?
import requests
from bs4 import BeautifulSoup
# URL of the webpage to scrape
url = "https://www.racingandsports.com.au/thoroughbred/horse/smokin-rubi/1978955"
# Define the user agent header
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
}
# Send a GET request to the URL with the user agent header
response = requests.get(url, headers=headers)
# Parse the HTML content of the page
soup = BeautifulSoup(response.content, 'html.parser')
# Find the table element with class 'table table-condensed table-striped table-hover tbl-race-form'
table_element = soup.find('table', class_='table table-condensed table-striped table-hover tbl-race-form')
# Check if the table element is found
if table_element:
# Extract text from the table
table_text = table_element.get_text(separator='n', strip=True)
print(table_text)
else:
print("No table with the specified class found on the page.")