我想要得到一个网站的代码。在本例中,它是一个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);
}这对任何正常的网站来说都是完美的。问题是它不能在这个tiktok站点上工作。
我认为这是因为URL中有一个@,而Java对它有问题。
感谢您的任何帮助
发布于 2020-08-22 03:20:00
您可以尝试这样的操作:
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);
}发布于 2020-08-22 03:12:29
https://stackoverflow.com/questions/63528462
复制相似问题