3

I am trying to extract dynamic links from this website but couldn't extract them.

But I extracted links i.e., static links successfully from this website

Sample Code:

public class JavaScript {

    public static void main(String[] args) throws IOException {
        Document doc = Jsoup.connect("http://economictimes.indiatimes.com/archive.cms").get();
        Elements links = doc.select("a[href]");
        for (Element element : links) {
            System.out.println(element.attributes());
        }
    }
}

Now I want to extract dynamic links from website i.e., when we click on date it will call a function and generates the link. How can I get those links using JAVA?

smac89
  • 39,374
  • 15
  • 132
  • 179
  • This page is HTML/Javascript. How are you going to pass that URL in your Java code? If you can do so, you can use that URL as a static URL as shown in your program. – Aakash Jun 15 '15 at 08:40
  • In website(http://economictimes.indiatimes.com/archive/year-2015,month-1.cms) page source there is code like this "" How can i extract the link – Jagadeesh Sinde Jun 15 '15 at 08:51
  • I meant to say, are you able to connect to URL http://economictimes.indiatimes.com/archive/year-2015,month-1.cms in your java code? If yes, there should be no difference at all to connect to this URL. You should be able to normally connect to it as you have done with the static one. – Aakash Jun 15 '15 at 08:59
  • Yes the code is able to connect to URL but couldn't get desired links. Just check the website what I need is links for days in that website. – Jagadeesh Sinde Jun 15 '15 at 14:03

1 Answers1

0

Jsoup is an HTML parser. It has no support for Javascript. So it won't be able to run the Javascript code generating dynamic links.

Use one of the solution below (to name a few) to acheive your goal:

Stephan
  • 41,764
  • 65
  • 238
  • 329