I'm trying to get html content by code below:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class Main {
public static String getHtmlContent(String urlAddress) {
URL url;
try {
url = new URL(urlAddress);
URLConnection conn = url.openConnection();
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder stringBuilder = new StringBuilder();
while ((inputLine = br.readLine()) != null) {
stringBuilder.append(inputLine);
}
br.close();
return stringBuilder.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
String urlEmpik = getHtmlContent("https://myduolife.com/shop/products/1/780,duolife-keratin-hair-complex.html");
System.out.println(urlEmpik);
}
}
The problem is that when I entered into this website and make (click by mouse) "view source code" on the website the HTML content is different than when I use my (above) Java code. This code works correctly for most websites, but there are some websites where it does not work I mean the HTML source code is different. I do not know what is the reason? Maybe it is connected with some special security on some websites? Thank you for help.
Aucun commentaire:
Enregistrer un commentaire