The website is https://www.punters.com.au/stats/ and the HTML button is Download CSV
import requests
from bs4 import BeautifulSoup
base_url = 'https://www.punters.com.au'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3','referer': 'https://www.google.com/'}
# Make a request to the URL and parse the HTML content
response = requests.get(base_url + '/stats/', headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')
# <a class="stats-csv" href="javascript:void(-1);">Download CSV</a>
csv = soup.find('a', class_="stats-csv")
print(csv)
This finds the button, but how is it executed?
Selenium appears to be the only option, and after matching the ChromeDriver I'm plodding away and have added the following code, which finds the download button but haven't yet managed the download.
# import modules
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
print("fetching csv button for {} ".format(base_url))
driver.get(base_url + '/stats/')
driver.implicitly_wait(2) # seconds
try:
assert "Free Australian Horse Racing Statistics - Punters.com.au" in driver.title
elem = driver.find_element(By.CLASS_NAME,"stats-csv").send_keys("webdriver" + Keys.ENTER)
except:
print ("\n%Error-website: {}\n".format(base_url + '/stats/'))