英文:
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()));
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);
}
英文:
I want to get the code of a website. In this case it's a tiktok page.
My code looks like this:
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);
}
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
你可以尝试类似这样的代码:
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);
}
英文:
You can try something like that:
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);
}
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论