Problem reading Website content with a get request in java











up vote
0
down vote

favorite












i'm trying to read the best price from the skyscanner website using a normal get request, but i'm not getting the content that i want by using this code.



private void getRequest() throws Exception {
StringBuilder result = new StringBuilder();
URL url = new URL(URL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.addRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0");
System.out.println(conn.getURL());
conn.setInstanceFollowRedirects(true);
HttpURLConnection.setFollowRedirects(true);
conn.setRequestMethod("GET");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(conn.getURL());
rd.close();
response = result.toString();
}


The requested URL is the following:



https://www.skyscanner.com/transport/flights/fra/txl/181220/?adults=1&children=0&adultsv2=1&childrenv2=&infants=0&cabinclass=economy&rtn=0&preferdirects=false&outboundaltsenabled=false&inboundaltsenabled=false&currency=EUR&market=DE&locale=en-US


Response from the code above looks like this:



https://pastebin.com/YKh17RKE


By going to the mentioned skyscanner link in chrome i can click on inspect element and voila under



 fqs-opts-container -> <span class="fqs-price">42 €</span>


i can see the cheapest price.



How to get this information using java? What am i doing wrong here?



Thanks in advance.










share|improve this question






















  • Inspect shows the current HTML DOM (Document Object Model) resulting from the static HTML page (View page source) plus dynamic modifications by JavaScript. If you go to Inspect, tab Network and reload the page, you can see which files (and their contents) are all requested by the browser to display the page.
    – howlger
    Nov 18 at 21:50












  • Thank you for the quick reply & the new information I have been checking everything in the network section but i still don't have any idea that might help me to solve the problem.
    – Ghaiss
    Nov 19 at 0:36

















up vote
0
down vote

favorite












i'm trying to read the best price from the skyscanner website using a normal get request, but i'm not getting the content that i want by using this code.



private void getRequest() throws Exception {
StringBuilder result = new StringBuilder();
URL url = new URL(URL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.addRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0");
System.out.println(conn.getURL());
conn.setInstanceFollowRedirects(true);
HttpURLConnection.setFollowRedirects(true);
conn.setRequestMethod("GET");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(conn.getURL());
rd.close();
response = result.toString();
}


The requested URL is the following:



https://www.skyscanner.com/transport/flights/fra/txl/181220/?adults=1&children=0&adultsv2=1&childrenv2=&infants=0&cabinclass=economy&rtn=0&preferdirects=false&outboundaltsenabled=false&inboundaltsenabled=false&currency=EUR&market=DE&locale=en-US


Response from the code above looks like this:



https://pastebin.com/YKh17RKE


By going to the mentioned skyscanner link in chrome i can click on inspect element and voila under



 fqs-opts-container -> <span class="fqs-price">42 €</span>


i can see the cheapest price.



How to get this information using java? What am i doing wrong here?



Thanks in advance.










share|improve this question






















  • Inspect shows the current HTML DOM (Document Object Model) resulting from the static HTML page (View page source) plus dynamic modifications by JavaScript. If you go to Inspect, tab Network and reload the page, you can see which files (and their contents) are all requested by the browser to display the page.
    – howlger
    Nov 18 at 21:50












  • Thank you for the quick reply & the new information I have been checking everything in the network section but i still don't have any idea that might help me to solve the problem.
    – Ghaiss
    Nov 19 at 0:36















up vote
0
down vote

favorite









up vote
0
down vote

favorite











i'm trying to read the best price from the skyscanner website using a normal get request, but i'm not getting the content that i want by using this code.



private void getRequest() throws Exception {
StringBuilder result = new StringBuilder();
URL url = new URL(URL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.addRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0");
System.out.println(conn.getURL());
conn.setInstanceFollowRedirects(true);
HttpURLConnection.setFollowRedirects(true);
conn.setRequestMethod("GET");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(conn.getURL());
rd.close();
response = result.toString();
}


The requested URL is the following:



https://www.skyscanner.com/transport/flights/fra/txl/181220/?adults=1&children=0&adultsv2=1&childrenv2=&infants=0&cabinclass=economy&rtn=0&preferdirects=false&outboundaltsenabled=false&inboundaltsenabled=false&currency=EUR&market=DE&locale=en-US


Response from the code above looks like this:



https://pastebin.com/YKh17RKE


By going to the mentioned skyscanner link in chrome i can click on inspect element and voila under



 fqs-opts-container -> <span class="fqs-price">42 €</span>


i can see the cheapest price.



How to get this information using java? What am i doing wrong here?



Thanks in advance.










share|improve this question













i'm trying to read the best price from the skyscanner website using a normal get request, but i'm not getting the content that i want by using this code.



private void getRequest() throws Exception {
StringBuilder result = new StringBuilder();
URL url = new URL(URL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.addRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0");
System.out.println(conn.getURL());
conn.setInstanceFollowRedirects(true);
HttpURLConnection.setFollowRedirects(true);
conn.setRequestMethod("GET");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(conn.getURL());
rd.close();
response = result.toString();
}


The requested URL is the following:



https://www.skyscanner.com/transport/flights/fra/txl/181220/?adults=1&children=0&adultsv2=1&childrenv2=&infants=0&cabinclass=economy&rtn=0&preferdirects=false&outboundaltsenabled=false&inboundaltsenabled=false&currency=EUR&market=DE&locale=en-US


Response from the code above looks like this:



https://pastebin.com/YKh17RKE


By going to the mentioned skyscanner link in chrome i can click on inspect element and voila under



 fqs-opts-container -> <span class="fqs-price">42 €</span>


i can see the cheapest price.



How to get this information using java? What am i doing wrong here?



Thanks in advance.







java eclipse






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 at 20:14









Ghaiss

115




115












  • Inspect shows the current HTML DOM (Document Object Model) resulting from the static HTML page (View page source) plus dynamic modifications by JavaScript. If you go to Inspect, tab Network and reload the page, you can see which files (and their contents) are all requested by the browser to display the page.
    – howlger
    Nov 18 at 21:50












  • Thank you for the quick reply & the new information I have been checking everything in the network section but i still don't have any idea that might help me to solve the problem.
    – Ghaiss
    Nov 19 at 0:36




















  • Inspect shows the current HTML DOM (Document Object Model) resulting from the static HTML page (View page source) plus dynamic modifications by JavaScript. If you go to Inspect, tab Network and reload the page, you can see which files (and their contents) are all requested by the browser to display the page.
    – howlger
    Nov 18 at 21:50












  • Thank you for the quick reply & the new information I have been checking everything in the network section but i still don't have any idea that might help me to solve the problem.
    – Ghaiss
    Nov 19 at 0:36


















Inspect shows the current HTML DOM (Document Object Model) resulting from the static HTML page (View page source) plus dynamic modifications by JavaScript. If you go to Inspect, tab Network and reload the page, you can see which files (and their contents) are all requested by the browser to display the page.
– howlger
Nov 18 at 21:50






Inspect shows the current HTML DOM (Document Object Model) resulting from the static HTML page (View page source) plus dynamic modifications by JavaScript. If you go to Inspect, tab Network and reload the page, you can see which files (and their contents) are all requested by the browser to display the page.
– howlger
Nov 18 at 21:50














Thank you for the quick reply & the new information I have been checking everything in the network section but i still don't have any idea that might help me to solve the problem.
– Ghaiss
Nov 19 at 0:36






Thank you for the quick reply & the new information I have been checking everything in the network section but i still don't have any idea that might help me to solve the problem.
– Ghaiss
Nov 19 at 0:36














1 Answer
1






active

oldest

votes

















up vote
0
down vote













Inspect shows the current HTML DOM (Document Object Model) resulting from:




  • the static HTML page (see right-click + View page source) plus

  • dynamic modifications by JavaScript.


If you do Inspect, tab Network and reload the page, you can see which files (and their contents) are all requested by the browser to display the page.



In this particular case, it seems that you could get the data as JSON:



In the tab Network filter for conductor/v1/fps3/search/. The query is an HTTP post request with the URL https://www.skyscanner.de/g/conductor/v1/fps3/search/?geo_schema=skyscanner&carrier_schema=skyscanner&response_include=query%3Bdeeplink%3Bsegment%3Bstats%3Bfqs%3Bpqs%3B_flights_availability. The answer is in JSON and includes a session_id which is required as part of the URL for subsequent requests for details.



Please note that even if it is technically possible to receive the data, it is in most cases forbidden to use them commercially.






share|improve this answer

















  • 1




    Thank you very much i will try this method. I don't intend to use it commercially, i only want to learn how these things work and maybe just enough to build my own price alarm.
    – Ghaiss
    Nov 19 at 13:53











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365011%2fproblem-reading-website-content-with-a-get-request-in-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Inspect shows the current HTML DOM (Document Object Model) resulting from:




  • the static HTML page (see right-click + View page source) plus

  • dynamic modifications by JavaScript.


If you do Inspect, tab Network and reload the page, you can see which files (and their contents) are all requested by the browser to display the page.



In this particular case, it seems that you could get the data as JSON:



In the tab Network filter for conductor/v1/fps3/search/. The query is an HTTP post request with the URL https://www.skyscanner.de/g/conductor/v1/fps3/search/?geo_schema=skyscanner&carrier_schema=skyscanner&response_include=query%3Bdeeplink%3Bsegment%3Bstats%3Bfqs%3Bpqs%3B_flights_availability. The answer is in JSON and includes a session_id which is required as part of the URL for subsequent requests for details.



Please note that even if it is technically possible to receive the data, it is in most cases forbidden to use them commercially.






share|improve this answer

















  • 1




    Thank you very much i will try this method. I don't intend to use it commercially, i only want to learn how these things work and maybe just enough to build my own price alarm.
    – Ghaiss
    Nov 19 at 13:53















up vote
0
down vote













Inspect shows the current HTML DOM (Document Object Model) resulting from:




  • the static HTML page (see right-click + View page source) plus

  • dynamic modifications by JavaScript.


If you do Inspect, tab Network and reload the page, you can see which files (and their contents) are all requested by the browser to display the page.



In this particular case, it seems that you could get the data as JSON:



In the tab Network filter for conductor/v1/fps3/search/. The query is an HTTP post request with the URL https://www.skyscanner.de/g/conductor/v1/fps3/search/?geo_schema=skyscanner&carrier_schema=skyscanner&response_include=query%3Bdeeplink%3Bsegment%3Bstats%3Bfqs%3Bpqs%3B_flights_availability. The answer is in JSON and includes a session_id which is required as part of the URL for subsequent requests for details.



Please note that even if it is technically possible to receive the data, it is in most cases forbidden to use them commercially.






share|improve this answer

















  • 1




    Thank you very much i will try this method. I don't intend to use it commercially, i only want to learn how these things work and maybe just enough to build my own price alarm.
    – Ghaiss
    Nov 19 at 13:53













up vote
0
down vote










up vote
0
down vote









Inspect shows the current HTML DOM (Document Object Model) resulting from:




  • the static HTML page (see right-click + View page source) plus

  • dynamic modifications by JavaScript.


If you do Inspect, tab Network and reload the page, you can see which files (and their contents) are all requested by the browser to display the page.



In this particular case, it seems that you could get the data as JSON:



In the tab Network filter for conductor/v1/fps3/search/. The query is an HTTP post request with the URL https://www.skyscanner.de/g/conductor/v1/fps3/search/?geo_schema=skyscanner&carrier_schema=skyscanner&response_include=query%3Bdeeplink%3Bsegment%3Bstats%3Bfqs%3Bpqs%3B_flights_availability. The answer is in JSON and includes a session_id which is required as part of the URL for subsequent requests for details.



Please note that even if it is technically possible to receive the data, it is in most cases forbidden to use them commercially.






share|improve this answer












Inspect shows the current HTML DOM (Document Object Model) resulting from:




  • the static HTML page (see right-click + View page source) plus

  • dynamic modifications by JavaScript.


If you do Inspect, tab Network and reload the page, you can see which files (and their contents) are all requested by the browser to display the page.



In this particular case, it seems that you could get the data as JSON:



In the tab Network filter for conductor/v1/fps3/search/. The query is an HTTP post request with the URL https://www.skyscanner.de/g/conductor/v1/fps3/search/?geo_schema=skyscanner&carrier_schema=skyscanner&response_include=query%3Bdeeplink%3Bsegment%3Bstats%3Bfqs%3Bpqs%3B_flights_availability. The answer is in JSON and includes a session_id which is required as part of the URL for subsequent requests for details.



Please note that even if it is technically possible to receive the data, it is in most cases forbidden to use them commercially.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 7:58









howlger

9,57051636




9,57051636








  • 1




    Thank you very much i will try this method. I don't intend to use it commercially, i only want to learn how these things work and maybe just enough to build my own price alarm.
    – Ghaiss
    Nov 19 at 13:53














  • 1




    Thank you very much i will try this method. I don't intend to use it commercially, i only want to learn how these things work and maybe just enough to build my own price alarm.
    – Ghaiss
    Nov 19 at 13:53








1




1




Thank you very much i will try this method. I don't intend to use it commercially, i only want to learn how these things work and maybe just enough to build my own price alarm.
– Ghaiss
Nov 19 at 13:53




Thank you very much i will try this method. I don't intend to use it commercially, i only want to learn how these things work and maybe just enough to build my own price alarm.
– Ghaiss
Nov 19 at 13:53


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365011%2fproblem-reading-website-content-with-a-get-request-in-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga