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¤cy=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(); } }