Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screen Scraping using JSoup

I want to get data from this web site with web scraping. http://myservices.ect.nl/tracing/objectstatus/Pages/Overview.aspx:

enter image description here

I used JSoup before for more static HTML sites, but this one is more difficult because before I get the HTML table on the site have to click one button and I don't know if it's possible to use JSoup to manipulate the button.

After click this button I get a HTML table, I want to get data only where modality is Barge.

Thank you for your tip to use Firefox, now I have the table with some another page information. Can you tell me how can i get only table information? Output that I get is as follows:

enter image description here

like image 722
Muratcan Avatar asked Aug 13 '26 04:08

Muratcan


1 Answers

You will have to use Selenium HTML Unit Driver for that.

Selenium Info

Maven/Download Binary JAR

HTML Unit Driver

Here is full working example. It will visit the website ,click the button and then you can get the data from the page.

Edit: Only get the table value

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class GetData {

    public static void main(String args[]) throws InterruptedException {
        WebDriver driver = new FirefoxDriver();
        driver.get("http://myservices.ect.nl/tracing/objectstatus/Pages/Overview.aspx");
        Thread.sleep(5000);
        // select barge
        new Select(driver.findElement(By.id("ctl00_ctl15_g_ce17bd4b_3803_47f6_822a_2b8dd10fc67d_ctl00_dlModality"))).selectByVisibleText("Barge");
        // click button
        Thread.sleep(3000);
        driver.findElement(By.className("button80")).click();
        Thread.sleep(5000);

        //get only table text
        WebElement findElement = driver.findElement(By.className("grid-view"));
        String htmlTableText = findElement.getText();
        // do whatever you want now, These are raw table values.
        System.out.println(htmlTableText);

        driver.close();
        driver.quit();    
    }
}
like image 91
Makky Avatar answered Aug 14 '26 18:08

Makky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!