检索正确的twitter html

6yoyoihd  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(165)

我正在研究一种方法来解析twitter中html代码中的特定链接:https://twitter.com/omarsaiyajin/status/1338866699039215619
我试过以下代码

public static String getHTMLWithDownloadLink() {
        String youtubeVideoURL = "https://twitter.com/OmarSaiyajin/status/1338866699039215619";
        URL url = null;
        HttpsURLConnection conn = null;
        StringBuilder sb = new StringBuilder();
        try {
            url = new URL(youtubeVideoURL);
            conn = (HttpsURLConnection) url.openConnection();

            conn.setDoOutput(true);
            conn.setInstanceFollowRedirects(false);
            conn.setRequestMethod("GET");
            DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
            BufferedReader reader = null;
            reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            return sb.toString();
    }

问题是返回字符串与浏览器中的html不匹配。我也试过 Postman ,它返回正确的html。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题