![](/img/trans.png)
[英]How to extract the text without HTML tags out of a webpage using HtmlUnit?
[英]Extract Text from Website without any HTML tags with selenium
您可以使用以下 xpath:
//strong[text()='Customer']/../following-sibling::div/descendant::div[starts-with(@class,'col-md-10')]
像這樣:
String gottenText = new WebDriverWait(driver, Duration.ofSeconds(20)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//strong[text()='Customer']/../following-sibling::div/descendant::div[@class='col-md-10']"))).getAttribute("innerText");
System.out.println(gottenText);
應提供以下 output:
Email user@phptravels.com
Password demouser
更新:
您可以將它們存儲到 String 變量中,如下所示:
String gottenText = new WebDriverWait(driver, Duration.ofSeconds(20)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//strong[text()='Customer']/../following-sibling::div/descendant::div[@class='col-md-10']"))).getAttribute("innerText");
String[] arr = gottenText.split(" ");
String[] userNames = arr[1].split("\\r?\\n");
String userName = userNames[0];
String password = arr[2];
System.out.println(userName + " " + password);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.