简体   繁体   English

使用jsoup从url获取内容

[英]using jsoup getting content from url

i want to get the entire content of url (ie) till the end of that url.. but after getting few contents because of partial loading ..i cant able to get remaining contents...is there is any way to get whole content from url even after the partial loading ... 我想获取url的全部内容(即,直到该URL的末尾..),但是由于部分加载而获得很少的内容。.我无法获取剩余的内容...有没有办法获取整个内容从URL即使部分加载后...

         String url = "URL/"; // getting URL
          try {
         Document doc = Jsoup.connect(url).get();
         FileWriter fw=null;
         BufferedWriter bw=null;
        fw=new FileWriter("D:\\url.txt");
        bw=new BufferedWriter(fw);
        String line = doc.text();
         System.out.println(line);
            bw.write(line);
        } catch (IOException ex) {
       Logger.getLogger(NewJFrame.class.getName())
       .log(Level.SEVERE, null,  ex);
    }

Sorry for the late answer, dinner... 对不起,迟到的答案,晚餐...

An answer can be found here: Read url to string in few lines of java code 在这里可以找到答案: 用几行Java代码读取url到字符串

Idk if it's your question is a duplicate question or not... 如果您的问题是重复的问题,那么请问一下IDK ...

Anyways, the traditional way to do it would be like this: 无论如何,传统的方式是这样的:

URL website = new URL("example.com");
        URLConnection connection = website.openConnection();
        BufferedReader in = new BufferedReader(
                                new InputStreamReader(
                                    connection.getInputStream()));

        StringBuilder response = new StringBuilder();
        String inputLine;

        while ((inputLine = in.readLine()) != null) 
            response.append(inputLine);

        in.close();

Hope I helped! 希望我能帮上忙!

    URL website;
    try {
        website = new URL("https://news.google.co.in/");

    URLConnection connection = website.openConnection();
    BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                                connection.getInputStream()));

    StringBuilder response = new StringBuilder();
    String inputLine;

    while ((inputLine = in.readLine()) != null) 
        response.append(inputLine);

    in.close();
        System.out.print(response.toString());
  } catch (MalformedURLException ex) {
                                                                                    Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
    Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

and getting an html output 并获取html输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM