我从网站上获取HTML代码,然后我想使用Jsoup从属性中获取值“ 31 983”:
<span class="counter nowrap">31 983</span>
下面的代码已准备就绪,但不要使用此值。你能帮我吗?
public class TestWebscrapper { private static WebDriver driver; @BeforeClass public static void before() { System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe"); driver = new ChromeDriver(); } @Test public void typeAllegroUserCodeIntoAllegroPageToAuthenticate() { String urlToAuthencicateToTypeUserCode="https://www.test.pl/"; driver.get(urlToAuthencicateToTypeUserCode); Document doc = Jsoup.parse(driver.getPageSource()); //how to take below value: System.out.println(doc.attr("counter nowrap")); } @AfterClass public static void after() { driver.quit(); } }
我试图使用
doc.attr
,但没有帮助。
我正在从网站上获取HTML代码,然后我想使用Jsoup从属性中获取值“ 31 983”:31 983
Jsoup使用CSS selectors在HTML源代码中查找元素。要实现您想要的功能,请使用: