Question

Hi I am trying to scrape data from a web site I want to auto select dropdown menu in that website and then capture all data from the table.

I am having a problem because in that website table id is not available there so I am confused how can I scrape that value.

Here is my code

public class Market {
    public static void main(String args[]) throws InterruptedException, ClassNotFoundException, SQLException {
      WebDriver driver = new HtmlUnitDriver(BrowserVersion.getDefault());
        String market="Rura";
        String url="http://www.upmandiparishad.in/CW_Rates_new.asp";
        driver.get(url);
        Thread.sleep(5000);
        new Select(driver.findElement(By.id("mktcode"))).selectByVisibleText(market);
        Thread.sleep(3000);
        Thread.sleep(5000);
        WebElement findElement = driver.findElement(By.id("what to give here"));
        String htmlTableText = findElement.getText();
        System.out.println(htmlTableText);
        driver.close();
        driver.quit();

    }
}

How can I achieve my output

Was it helpful?

Solution

The problem with asking someone who stops by a question for an answer by name is that they might not be knowledgeable about the some of the parts of your question. That said I'd try the following which should return a collection of the 5 tables on the page.

driver.findElements(By.tagName("table"));

If/When this doesn't work take a look at http://docs.seleniumhq.org/docs/03_webdriver.jsp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top