我正在尝试获取网站的HTML页面源代码。但我无法获得一些图像链接,我认为这些链接是在网页上动态填充的。
我使用java作为:
url = new URL(firstLevelURL);
connection = (HttpURLConnection) url.openConnection();
try ( // Read all the text returned by the server
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"))) {
// Read each line of "in" until done, adding each to "response"
while ((str = br.readLine()) != null) {
// str is one line of text readLine() strips newline characters
//I am not able to get this image as it is loaded dynamically using javascript/ajax or something.
if(str.contains("<img id=\"tileImage")) {
response = str;
break;
}
}
}
我尝试过使用: connection.setReadTimeout(15 * 1000); 但该页面仍未完全加载
在获取HTML源代码之前是否有任何方法可以等待页面完全加载