Java从Tiktok获取URL

huangapple go评论134阅读模式
英文:

Java get URL from Tiktok

问题

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

  1. String inputLine;
  2. while((inputLine = in.readLine()) != null) {
  3. System.out.println(inputLine);
  4. }

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

英文:

I want to get the code of a website. In this case it's a tiktok page.

My code looks like this:

  1. try {
  2. URL url = new URL("https://www.tiktok.com/@petyyyyyy?lang=de");
  3. BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
  4. String inputLine;
  5. while((inputLine = in.readLine()) != null) {
  6. System.out.println(inputLine);
  7. }
  8. } catch (MalformedURLException me) {
  9. System.out.println(me);
  10. } catch (IOException ioe) {
  11. System.out.println(ioe);
  12. }

This works perfect for any normal website. The problem is that it doesnt' work with this tiktok site.

I think it's because there is an @ in the URL and Java has a problem with it.

Any help appreciated

答案1

得分: 1

你可以尝试类似这样的代码:

  1. try {
  2. URL url = new URL("https://www.tiktok.com/%40petyyyyyy?lang=de");
  3. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  4. connection.setRequestProperty ("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0");
  5. BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  6. String inputLine;
  7. while ((inputLine = in.readLine()) != null) {
  8. System.out.println(inputLine);
  9. }
  10. } catch (MalformedURLException me) {
  11. System.out.println(me);
  12. } catch (IOException ioe) {
  13. System.out.println(ioe);
  14. }
英文:

You can try something like that:

  1. try {
  2. URL url = new URL("https://www.tiktok.com/%40petyyyyyy?lang=de");
  3. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  4. connection.setRequestProperty ("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0");
  5. BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  6. String inputLine;
  7. while ((inputLine = in.readLine()) != null) {
  8. System.out.println(inputLine);
  9. }
  10. } catch (MalformedURLException me) {
  11. System.out.println(me);
  12. } catch (IOException ioe) {
  13. System.out.println(ioe);
  14. }

答案2

得分: 0

好的,以下是您要翻译的内容:

似乎TikTok正在阻止对用户页面的请求。

解决方法:

在我的情况下,我只是想从网站上获取关注者人数。

我只需使用另一个网站,即tiktok关注者计数器

英文:

It looks like Tiktok is blocking requests to the user page.

Workaround:

In my case, I just wanted to get the follower amount from the site.

I simply use another website, i.e. tiktok follower counter

huangapple
  • 本文由 发表于 2020年8月22日 02:43:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63528462.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定