Selenium would be a good way to go to simulate the process of opening the page, then clicking the button. Then it waits for the test to finish and grabs the results.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
driver = webdriver.Chrome("C:/chromedriver_win32/chromedriver.exe")
driver.get("http://www.bredbandskollen.se/")
driver.find_element_by_id("mainStartTest").click()
# Waits until test is complete. Timesout after 60 seconds
WebDriverWait(driver, 60).until(ec.presence_of_element_located((By.XPATH, './/span[@class = "bbk-test-info-value" and text() != ""]')))
# Get the results
results = driver.find_elements_by_xpath('.//span[@class = "bbk-test-box-result"]')
dlSpeed = results[0].text
ulSpeed = results[1].text
ltSpeed = results[2].text
print ('Results\nDownloading: %s\nUploading: %s\nLatency: %s' %(dlSpeed, ulSpeed, ltSpeed))
driver.close()
Output:
Results
Downloading: 39,86 Mbit/s
Uploading: 4,16 Mbit/s
Latency: 240,15 ms
You could still use BeautifulSoup, but that wouldn't come until after the test is run. But not really needed, but at least lets you see how selenium and beautifulsoup are used to find the tags with the data you want:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
import bs4
driver = webdriver.Chrome("C:/chromedriver_win32/chromedriver.exe")
driver.get("http://www.bredbandskollen.se/")
driver.find_element_by_id("mainStartTest").click()
# Waits until test is complete. Timesout after 60 seconds
WebDriverWait(driver, 60).until(ec.presence_of_element_located((By.XPATH, './/span[@class = "bbk-test-info-value" and text() != ""]')))
# Get the results
soup = bs4.BeautifulSoup(driver.page_source, 'html.parser')
results = soup.find_all('span', {'class':'bbk-test-box-result'})
dlSpeed = results[0].text
ulSpeed = results[1].text
ltSpeed = results[2].text
print ('Results\nDownloading: %s\nUploading: %s\nLatency: %s' %(dlSpeed, ulSpeed, ltSpeed))
driver.close()