abhi
abhi

Reputation: 117

Reading webpage's inspect element data using java

I have a requirement . I am reading file from a dynamic web page , and the values which i require from the webpage lies within

<td>

, and this is visible when i inspect this element . So my question is , is it somehow possible to print the data contained in the inspect element using java?

Upvotes: 1

Views: 1993

Answers (2)

abhi
abhi

Reputation: 117

I found the solution to this one , leaving this answer in case if anyone stuck into this in future.

To print whatever you see inside inspect element can be tracked down using selenium.

Here's the code which i used `

WebDriver driver= new ChromeDriver();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://www.whatever.com");
Thread.sleep(1000);
List<WebElement> frameList = driver.findElements(By.tagName("frame"));
System.out.println(frameList.size());
driver.switchTo().frame(0);               
String temp=driver.findElement(By.xpath("/html/body/table/thead/tr/td/div[2]/table/thead/tr[2]/td[2]")).getText();

read here for more .

Upvotes: 1

Prashant
Prashant

Reputation: 5383

Using JSOUP. Here is the cookbook

ArrayList<String> downServers = new ArrayList<>();
Element table = doc.select("table").get(0);
Elements rows = table.select("tr");

for (int i = 1; i < rows.size(); i++) { 
    Element row = rows.get(i);
    Elements cols = row.select("td");

    // Use cols.get(index) to get the data from td element
}

Upvotes: 1

Related Questions