soup.find("div", {"class":"real number"})['data-value']
Here you are searching for a div
element, but the span
has the "real number" class in your example HTML data, try instead:
soup.find("span", {"class": "real number", "data-value": True})['data-value']
Here we are also checking for presence of data-value
attribute.
To find elements having "real number" or "fake number" classes, you can make a CSS selector:
for elm in soup.select(".real.number,.fake.number"):
print(elm.get("data-value"))
To get the 69%
value:
soup.find("div", {"class": "percentage good"}).get_text(strip=True)
Or, a CSS selector:
soup.select_one(".percentage.good").get_text(strip=True)
soup.select_one(".score .percentage").get_text(strip=True)
Or, locating the h6
element having Audit score
text and then getting the preceding sibling:
soup.find("h6", text="Audit score").previous_sibling.get_text(strip=True)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…