Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java从Tiktok获取URL_Java_Url - Fatal编程技术网

Java从Tiktok获取URL

Java从Tiktok获取URL,java,url,Java,Url,我想得到一个网站的代码。在这种情况下,它是一个提示页面 我的代码如下所示: try { URL url = new URL("https://www.tiktok.com/@petyyyyyy?lang=de"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String inputLine;

我想得到一个网站的代码。在这种情况下,它是一个提示页面

我的代码如下所示:

  try {
        URL url = new URL("https://www.tiktok.com/@petyyyyyy?lang=de");
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

        String inputLine;

        while((inputLine = in.readLine()) != null) {
            System.out.println(inputLine);
        }

    } catch (MalformedURLException me) {
        System.out.println(me);
    } catch (IOException ioe) {
        System.out.println(ioe);
    }
这适用于任何普通网站。问题是,它与这个tiktok站点不兼容

我认为这是因为URL中有一个@,Java对此有问题


感谢任何帮助

看起来Tiktok正在阻止对用户页面的请求

解决方法:

在我的例子中,我只是想从网站上获取关注者数量


我只需使用另一个网站,即

您可以尝试以下内容:

try {
        URL url = new URL("https://www.tiktok.com/%40petyyyyyy?lang=de");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty ("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0");
        
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

        String inputLine;

        while ((inputLine = in.readLine()) != null) {
            System.out.println(inputLine);
        }

    } catch (MalformedURLException me) {
        System.out.println(me);
    } catch (IOException ioe) {
        System.out.println(ioe);
    }

请尝试对其进行编码,即用“%40”替换url中的“@”,不幸的是,这没有帮助。它仍然不返回任何内容“不工作”不是我们可以调试的问题。很可能,这是一个基于JavaScript的网站。
URL=newURL(“https://www.tiktok.com/notfound");
对于此url,它工作正常。该站点可以查看您的用户代理,如果发现它不是公认的现代浏览器,它可以发送回一个空请求,可能是为了停止爬虫。如果你没有得到一个异常,那么这就是问题所在,你真的无能为力。tiktok和其他社交媒体网站有很大的动机来阻止爬虫,你可能无法绕过它。