Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.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 解析URL并检索信息_Java - Fatal编程技术网

Java 解析URL并检索信息

Java 解析URL并检索信息,java,Java,我需要提取Google Play应用程序的类别。例如,Facebook属于“社交”类 所以我需要从中获取社会信息。我能够在下面的代码中获得名为“result”的字符串中的HTML内容。但是我找不到包含类别名称的标签。我可以在检查元素时查看类别名称,但不能在代码中查看。如何获取上述URL的完整html内容,代码中的URL没有完整的html内容。类别名称在下面 html,标题,脚本,正文,div,“类别名称” 当我阅读完整的HTML响应时,我只得到以下标记元素:,,,但我没有得到元素及其内容。为什么

我需要提取Google Play应用程序的类别。例如,Facebook属于“社交”类

所以我需要从中获取社会信息。我能够在下面的代码中获得名为“result”的字符串中的HTML内容。但是我找不到包含类别名称的标签。我可以在检查元素时查看类别名称,但不能在代码中查看。如何获取上述URL的完整html内容,代码中的URL没有完整的html内容。类别名称在下面 html,标题,脚本,正文,div,“类别名称”

当我阅读完整的HTML响应时,我只得到以下标记元素:
,但我没有得到
元素及其内容。为什么没有返回页面的正文内容

下面的代码输出查询页面的HTML响应

String url = "https://play.google.com/store/apps/details?id=com.kongregate.mobile.fly.google&hl=en";
InputStream inputStream = null;
String result = "";

try {

    // create HttpClient
    HttpClient httpclient = new DefaultHttpClient();

    // make GET request to the given URL
    HttpResponse httpResponse = httpclient.execute(new HttpGet(url));
    EntityUtils.toString(httpResponse.getEntity());
    inputStream = httpResponse.getEntity().getContent();

    // convert InputStream to String
    if (inputStream != null) {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
        String line = "";

        while((line = bufferedReader.readLine()) != null) {
            result += line;
        }
    }
    // ...
} catch(...) {...}

也许这会有所帮助,代码会将整个网站作为文档返回:

org.jsoup.nodes.Document html = null;
try {
    html = Jsoup.connect(source).get();
} catch (final IOException e) {
    LOG.error(e.getMessage(), e);
}
LOG.info(html);
使用

我没有找到您的“类别名称”节点,但您可能会再次找到;) 您可以通过以下方式搜索文档:

html.select("#Category Name");

将URL输入web浏览器时会发生什么情况?