Subtract HTML-code page for the price in EUR

When opening the site by default, the price is set in US Dollar and parsed without problems:

String siteAddress = "https://www.globalpetrolprices.com/gasoline_prices/"; Document doc = Jsoup.connect(siteAddress).get(); 

Etc.

And what about the price in EUR? I tried this:

 String siteAddress = "https://www.globalpetrolprices.com/gasoline_prices/?currency=EUR"; 

But all the same, the dollar values ​​are calculated!


Redid the code to make it easier without Jsoup. What else to add now? I do not really understand where to attach POST here :-(

 import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.List; public class FuelPreisService { public static void main(String[] args) throws Exception { String siteAddress = "https://www.globalpetrolprices.com/gasoline_prices/?literGalon=1&currency=EUR"; String httpContent = getContentOfHTTPPage(siteAddress); List<String> preisFuel = getPreisFuel(httpContent); System.out.println(preisFuel); } private static List<String> getPreisFuel(String httpContent) throws Exception { List<String> result = new ArrayList<String>(); String[] array1 = httpContent.split("data="); String st1 = array1[1]; String[] array2 = st1.split("&titles"); String prices = array2[0]; String[] array3 = prices.split(","); for (int i = 0; i < array3.length; i++) { result.add((array3[i])); } return result; } private static String getContentOfHTTPPage(String pageAddress) throws Exception { StringBuilder sb = new StringBuilder(); URL pageURL = new URL(pageAddress); URLConnection uc = pageURL.openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream())); try { String inputLine; while ((inputLine = br.readLine()) != null) { sb.append(inputLine); } } finally { br.close(); } return sb.toString(); } } 

    1 answer 1

    Send with the POST method:

     Request URL: https://www.globalpetrolprices.com/gasoline_prices/ Request Method: POST FormData: literGalon=1&currency=EUR 

    In response, get 302 Moved Temporarily on the page you need. Apparently this value is stored in the session. Do not forget to read, save and substitute in the next request a cookie from the header.

     Set-Cookie:PHPSESSID=тут будет id вашей сессии; path=/ 
    • Redid the code to be simpler, without Jsoup. What else to add now? I don’t really understand where to attach the POST here :-( The code is added to the first message - Solenoid2200
    • @Solenoid I'm not strong in java, but Google knows - stackoverflow.com/questions/2026260/… - Darth