我试图在网站https://launch.stellar.org/#/login中获取所有标签HTML。
但我的结果没有任何输入标签,就像我在Firefox中的F12工具中看到这个网站。
我不明白为什么以及这个问题的解决方案是什么?
这是我的代码:
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import javax.net.ssl.HttpsURLConnection;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.helper.HttpConnection.Response;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class HttpUrlConnect {
private HttpsURLConnection conn;
private final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36";
public static void main(String[] args) throws Exception {
String url = "https://launch.stellar.org/#/login";
HttpUrlConnect http = new HttpUrlConnect();
// 1. Send a "GET" request, so that you can extract the form's data.
String page = http.GetPageContent(url);
Document doc = Jsoup.parse(page);
System.out.println(doc);
}
String GetPageContent(String url) throws Exception {
URL obj = new URL(url);
conn = (HttpsURLConnection) obj.openConnection();
// default is GET
conn.setRequestMethod("GET");
conn.setUseCaches(false);
// act like a browser
conn.setRequestProperty("Host", "wallet.stellar.org");
conn.setRequestProperty("User-Agent", USER_AGENT);
conn.setRequestProperty("Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
conn.setRequestProperty("Accept-Language", "vi-VN,vi;q=0.8,fr-FR;q=0.6,fr;q=0.4,en- US;q=0.2,en;q=0.2");
int responseCode = conn.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
BufferedReader in =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return response.toString();
}
我在这里下载jsoup库:http://jsoup.org/download
来自服务器端的文本与从jsoup获得的输出相同
在Web浏览器中加载页面后,使用javascript动态创建输入标记,因此只有您无法看到输入标记。