I am trying to scrape this webpage
I want to get the content from the following table:
The Statistics table content is present inside: div tag having "srl-tab srl-tab-handball-playerstats sr-widget sr-widget-level-0 sr-handball-playerstats sr-normal" as class-name
I am using the following code:
from selenium import webdriver
from bs4 import BeautifulSoup
link = "https://www.liquimoly-hbl.de/en/import/games/season-2020-2021/bundesliga/21--gameday--rhein-neckar-loewen---eulen-ludwigshafen/"
driver = webdriver.Chrome("path-to-my-chromedrivers")
driver.get(link)
driver.switch_to.frame("iframe-23400665")
page_source = driver.page_source
driver.close()
soup = BeautifulSoup(page_source, "html5lib")
a = soup.find("div", {"class": "srl-tabs-wrapper srl-flex-child"}).find("div", {"srl-tabs srl-flex"}).find("div", {'class': "srl-tabs-content-wrapper srl-flex-child"}).find("div", {"class": "srl-tabs-content"})
print(a.find("div", {"class": "srl-tab srl-tab-handball-playerstats sr-widget sr-widget-level-0 sr-handball-playerstats sr-normal"}))
The output of the print statement is giving me "None" value, since there is a div tag present in the website with the same class name I don't know why I am not getting the required output.
What is the thing that I have to change in my code? Or am I doing something wrong here?
Edit:
I think the only way to get the Statistics table value from the page-source is by first clicking on the Statistics button and then extracting the page-source. I do not know how to click on the Statistics button,
driver = webdriver.Chrome('path-to-my-chromedrivers')
driver.get(link)
driver.switch_to.frame("iframe-23400665")
page_source = driver.page_source
x = driver.find_elements_by_xpath("//div[@class='srl-tab']")
for i in x:
if i.get_attribute("data-widget") == "handball.playerstats":
print(i.get_attribute("class"))
print(i.get_attribute("data-widget"))
driver.execute_script("arguments[0].click();", i)
print(i.get_attribute("class"))
page_source_2 = driver.page_source
break
driver.close()
Output:-
srl-tab
handball.playerstats
srl-tab selected
I am now able to click on the Statistics button (see class srl-tab changes to srl-tab selected)
But still no luck with getting the Player Total table.
