1

I'm parsing html page that uses javascript function call to show data. I need that data, I know how to parse the page to get function body, but the question is how to call that function from my java program to receive the same data function returns when is called on the site?

EDIT: the concrete web page is http://hedonism.co.uk/wines/, function to display wines is called getWines(), I need all wines info.

Martin
  • 767
  • 2
  • 9
  • 21
  • can you add your sample of code to the question – vikeng21 Mar 28 '14 at 13:19
  • What does that JavaScript function do exactly? Is it web- or browser-related? – kol Mar 28 '14 at 13:19
  • @vikeng21 I updated, please take a look at. – Martin Mar 28 '14 at 13:49
  • @kol sorry I don't get the question. What is the difference? – Martin Mar 28 '14 at 13:50
  • (1) If the code is related to the web browser, then you need to simulate the browser in the Java code (for example, with a headless browser, see Ben's answer). (2) If there is no need to simulate the browser, then the JavaScript can be run by the Rhino engine. If the JavaScript uses the web (AJAX), then this is harder, but seems to be possible: http://www.javaworld.com/article/2077796/java-se/ajax-programming-with-the-java-scripting-api.html?page=4 – kol Mar 28 '14 at 14:36

2 Answers2

2

Just simply running the JavaScript code on that webpage is not going to cut it, you will have to simulate a browser environment to get reliable results. I suggest you take a look at the list in the correct answer to "automation - headless internet browser" for inspiration.

Community
  • 1
  • 1
Ben Barkay
  • 5,473
  • 2
  • 20
  • 29
0

Looks like you have similar problem

One of the solutions is to use Selenium to record web page interaction scenario and use that scenario from java

Community
  • 1
  • 1
Nazarii Bardiuk
  • 4,272
  • 1
  • 19
  • 22