在类似的情况下,我使用下面的代码获得了一个数字。
from requests import get from bs4 import BeautifulSoup pagina = "https://example" response = get(pagina) soup = BeautifulSoup(response.text, "html.parser") cont = soup.find(class_="Trsdu(0.3s)") print(cont.text)
这是字符串操作中的一个简单练习:
String fullText = driver.findElement(By.className("card-platform")).getText(); assert fullText.equals("Hosted at the \nANDROID\n app store"); String prefix = driver.findElements(By.className("sr-only")).get(0).getText(); String suffix = driver.findElements(By.className("sr-only")).get(1).getText(); assert prefix.equals("Hosted at the "); assert suffix.equals(" app store"); String yourText = fullText.replace(prefix, "").replace(suffix, ""); assert yourText.equals("ANDROID");
当然,您必须针对所有不同情况调整定位器。这是基于您提供的微小代码段示例。