Java 我已尝试访问该网站的内容:http://paraphrase.org/#/search?q=tree&过滤器=&;朗=恩
我尝试访问以下网站的内容:为了通过查询,不幸的是我没有获得内容(检索到的答案)。我将非常感谢任何帮助,这是我的代码Java 我已尝试访问该网站的内容:http://paraphrase.org/#/search?q=tree&过滤器=&;朗=恩,java,Java,我尝试访问以下网站的内容:为了通过查询,不幸的是我没有获得内容(检索到的答案)。我将非常感谢任何帮助,这是我的代码 import java.net.*; import java.io.*; public class PPdbURL { public static void main(String args[]) throws URISyntaxException{ String nextLine; URL url
import java.net.*;
import java.io.*;
public class PPdbURL {
public static void main(String args[]) throws URISyntaxException{
String nextLine;
URL url = null;
URLConnection urlConn = null;
InputStreamReader inStream = null;
BufferedReader buff = null;
try{ // Create the URL obect that points at the default file index.html
url = new URL("http://paraphrase.org/#/search?q=tree&filter=&lang=en" );
urlConn = url.openConnection();
inStream = new InputStreamReader(urlConn.getInputStream());
buff= new BufferedReader(inStream); // Read and print the lines from
//index.html
while (true){
nextLine =buff.readLine();
if (nextLine !=null){
System.out.println(nextLine);
}
else{
break;
}
}
}
catch(MalformedURLException e)
{
System.out.println("Please check the URL:" + e.toString() );
}
catch(IOException e1){
System.out.println("Can't read from the Internet: "+ e1.toString() );
}
}
}
当你说你没有得到内容时,你的意思是你没有得到正确的内容吗?我已经尝试了你的代码,它工作得很好,也就是说,我确实得到了HTTP响应 要认识到上面的代码片段,您不能使用上面的URL向服务器发出HTTP请求,并期望它的行为类似于解释web页面。这是因为URL中的片段标识符(“#”) RFC 3986和RFC 1738都解释了在解除隔离时,片段标识符不是URL或URI的一部分,应该删除片段标识符之后的所有内容 因此,在上面的示例中,URL连接仅用于 在检查解释web文档时,查询和搜索实际上是使用javascript激活的,在客户端上,在不同的URL上操作。向正在返回JSON资源的端点发出请求。然后,客户端上的javascript将解析结果并将结果呈现给浏览器 此HTTP请求的URL如下所示: 如您所见,这将生成搜索结果数据
因此,在您的示例中,应该考虑使用相同的URL,而将响应体作为ESOPRET作为JSON。有许多库可以帮助您做到这一点:
你得到了什么?例外?空内容?我试图发布输出,但太长了。基本上,它只是html,但最后指出的元素与Java脚本有关:您的答案太棒了,我非常满意,我非常感谢,尽管我想知道如何获取查询的URL。