How can I print the contents of this HTML table using JSoup?












0















I will start off by stating that working with HTML and JSoup for that matter is very foreign to me so if this comes across as a stupid question, I apologize.



What I am trying to achieve with my code is to print the contents from the table on this link https://www.stormshield.one/pve/stats/daviddean/sch into my console in a format like this for each entry:



Wall Launcher
50
grade grade grade grade grade
15% ImpactKnockback
42% Reload Speed
15% Impact Knockback
42% Reload Speed
15% ImpactKnockback
42% Durability



My main issue is pretty much supplying the correct name for the table and the rows, once I can do that the formatting isn't really an issue for me.



This is the code I have tried to use to no avail:



    public static void main(String args) throws IOException {

Document doc = Jsoup.connect("https://www.stormshield.one/pve/stats/daviddean/sch").get();

for (Element table : doc.select("table schematics")) {
for (Element row : table.select("tr")) {
Elements tds = row.select("td");
System.out.println(tds.get(0).text() + ":" + tds.get(1).text());
}
}

}









share|improve this question





























    0















    I will start off by stating that working with HTML and JSoup for that matter is very foreign to me so if this comes across as a stupid question, I apologize.



    What I am trying to achieve with my code is to print the contents from the table on this link https://www.stormshield.one/pve/stats/daviddean/sch into my console in a format like this for each entry:



    Wall Launcher
    50
    grade grade grade grade grade
    15% ImpactKnockback
    42% Reload Speed
    15% Impact Knockback
    42% Reload Speed
    15% ImpactKnockback
    42% Durability



    My main issue is pretty much supplying the correct name for the table and the rows, once I can do that the formatting isn't really an issue for me.



    This is the code I have tried to use to no avail:



        public static void main(String args) throws IOException {

    Document doc = Jsoup.connect("https://www.stormshield.one/pve/stats/daviddean/sch").get();

    for (Element table : doc.select("table schematics")) {
    for (Element row : table.select("tr")) {
    Elements tds = row.select("td");
    System.out.println(tds.get(0).text() + ":" + tds.get(1).text());
    }
    }

    }









    share|improve this question



























      0












      0








      0








      I will start off by stating that working with HTML and JSoup for that matter is very foreign to me so if this comes across as a stupid question, I apologize.



      What I am trying to achieve with my code is to print the contents from the table on this link https://www.stormshield.one/pve/stats/daviddean/sch into my console in a format like this for each entry:



      Wall Launcher
      50
      grade grade grade grade grade
      15% ImpactKnockback
      42% Reload Speed
      15% Impact Knockback
      42% Reload Speed
      15% ImpactKnockback
      42% Durability



      My main issue is pretty much supplying the correct name for the table and the rows, once I can do that the formatting isn't really an issue for me.



      This is the code I have tried to use to no avail:



          public static void main(String args) throws IOException {

      Document doc = Jsoup.connect("https://www.stormshield.one/pve/stats/daviddean/sch").get();

      for (Element table : doc.select("table schematics")) {
      for (Element row : table.select("tr")) {
      Elements tds = row.select("td");
      System.out.println(tds.get(0).text() + ":" + tds.get(1).text());
      }
      }

      }









      share|improve this question
















      I will start off by stating that working with HTML and JSoup for that matter is very foreign to me so if this comes across as a stupid question, I apologize.



      What I am trying to achieve with my code is to print the contents from the table on this link https://www.stormshield.one/pve/stats/daviddean/sch into my console in a format like this for each entry:



      Wall Launcher
      50
      grade grade grade grade grade
      15% ImpactKnockback
      42% Reload Speed
      15% Impact Knockback
      42% Reload Speed
      15% ImpactKnockback
      42% Durability



      My main issue is pretty much supplying the correct name for the table and the rows, once I can do that the formatting isn't really an issue for me.



      This is the code I have tried to use to no avail:



          public static void main(String args) throws IOException {

      Document doc = Jsoup.connect("https://www.stormshield.one/pve/stats/daviddean/sch").get();

      for (Element table : doc.select("table schematics")) {
      for (Element row : table.select("tr")) {
      Elements tds = row.select("td");
      System.out.println(tds.get(0).text() + ":" + tds.get(1).text());
      }
      }

      }






      java web-scraping jsoup






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 '18 at 20:28









      Brian Tompsett - 汤莱恩

      4,2031338101




      4,2031338101










      asked Nov 25 '18 at 13:34









      DavidDavid

      214




      214
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You need to find your table element, and it's head and rows.



          Be careful, it is not always the first() element, I add it as an example.



          Here is what you need to do:



          Document doc = null;
          try {
          doc = Jsoup.connect("https://www.stormshield.one/pve/stats/daviddean/sch").get();
          } catch (IOException e) {
          e.printStackTrace();
          }

          Element table = doc.body().getElementsByTag("table").first();

          Element thead = table.getElementsByTag("thead").first();

          StringBuilder headBuilder = new StringBuilder();

          for (Element th : thead.getElementsByTag("th")) {
          headBuilder.append(th.text());
          headBuilder.append(" ");
          }

          System.out.println(headBuilder.toString());

          Element tbody = table.getElementsByTag("tbody").first();

          for (Element tr : tbody.getElementsByTag("tr")) {
          StringBuilder rowBuilder = new StringBuilder();

          for (Element td : tr.getElementsByTag("td")) {
          rowBuilder.append(td.text());
          rowBuilder.append(" ");
          }
          System.out.println(rowBuilder.toString());
          }


          The output is :



          enter image description here






          share|improve this answer
























          • Incredible. Works flawlessly. Just wondering, how did you know the names of things like tbody and tr, td?

            – David
            Nov 25 '18 at 13:54











          • Well, it is just html. If you want to extract data from a web page, just right click inspect and take a look it's html. You find the required information there.

            – Emre Savcı
            Nov 25 '18 at 13:56













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468012%2fhow-can-i-print-the-contents-of-this-html-table-using-jsoup%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You need to find your table element, and it's head and rows.



          Be careful, it is not always the first() element, I add it as an example.



          Here is what you need to do:



          Document doc = null;
          try {
          doc = Jsoup.connect("https://www.stormshield.one/pve/stats/daviddean/sch").get();
          } catch (IOException e) {
          e.printStackTrace();
          }

          Element table = doc.body().getElementsByTag("table").first();

          Element thead = table.getElementsByTag("thead").first();

          StringBuilder headBuilder = new StringBuilder();

          for (Element th : thead.getElementsByTag("th")) {
          headBuilder.append(th.text());
          headBuilder.append(" ");
          }

          System.out.println(headBuilder.toString());

          Element tbody = table.getElementsByTag("tbody").first();

          for (Element tr : tbody.getElementsByTag("tr")) {
          StringBuilder rowBuilder = new StringBuilder();

          for (Element td : tr.getElementsByTag("td")) {
          rowBuilder.append(td.text());
          rowBuilder.append(" ");
          }
          System.out.println(rowBuilder.toString());
          }


          The output is :



          enter image description here






          share|improve this answer
























          • Incredible. Works flawlessly. Just wondering, how did you know the names of things like tbody and tr, td?

            – David
            Nov 25 '18 at 13:54











          • Well, it is just html. If you want to extract data from a web page, just right click inspect and take a look it's html. You find the required information there.

            – Emre Savcı
            Nov 25 '18 at 13:56


















          1














          You need to find your table element, and it's head and rows.



          Be careful, it is not always the first() element, I add it as an example.



          Here is what you need to do:



          Document doc = null;
          try {
          doc = Jsoup.connect("https://www.stormshield.one/pve/stats/daviddean/sch").get();
          } catch (IOException e) {
          e.printStackTrace();
          }

          Element table = doc.body().getElementsByTag("table").first();

          Element thead = table.getElementsByTag("thead").first();

          StringBuilder headBuilder = new StringBuilder();

          for (Element th : thead.getElementsByTag("th")) {
          headBuilder.append(th.text());
          headBuilder.append(" ");
          }

          System.out.println(headBuilder.toString());

          Element tbody = table.getElementsByTag("tbody").first();

          for (Element tr : tbody.getElementsByTag("tr")) {
          StringBuilder rowBuilder = new StringBuilder();

          for (Element td : tr.getElementsByTag("td")) {
          rowBuilder.append(td.text());
          rowBuilder.append(" ");
          }
          System.out.println(rowBuilder.toString());
          }


          The output is :



          enter image description here






          share|improve this answer
























          • Incredible. Works flawlessly. Just wondering, how did you know the names of things like tbody and tr, td?

            – David
            Nov 25 '18 at 13:54











          • Well, it is just html. If you want to extract data from a web page, just right click inspect and take a look it's html. You find the required information there.

            – Emre Savcı
            Nov 25 '18 at 13:56
















          1












          1








          1







          You need to find your table element, and it's head and rows.



          Be careful, it is not always the first() element, I add it as an example.



          Here is what you need to do:



          Document doc = null;
          try {
          doc = Jsoup.connect("https://www.stormshield.one/pve/stats/daviddean/sch").get();
          } catch (IOException e) {
          e.printStackTrace();
          }

          Element table = doc.body().getElementsByTag("table").first();

          Element thead = table.getElementsByTag("thead").first();

          StringBuilder headBuilder = new StringBuilder();

          for (Element th : thead.getElementsByTag("th")) {
          headBuilder.append(th.text());
          headBuilder.append(" ");
          }

          System.out.println(headBuilder.toString());

          Element tbody = table.getElementsByTag("tbody").first();

          for (Element tr : tbody.getElementsByTag("tr")) {
          StringBuilder rowBuilder = new StringBuilder();

          for (Element td : tr.getElementsByTag("td")) {
          rowBuilder.append(td.text());
          rowBuilder.append(" ");
          }
          System.out.println(rowBuilder.toString());
          }


          The output is :



          enter image description here






          share|improve this answer













          You need to find your table element, and it's head and rows.



          Be careful, it is not always the first() element, I add it as an example.



          Here is what you need to do:



          Document doc = null;
          try {
          doc = Jsoup.connect("https://www.stormshield.one/pve/stats/daviddean/sch").get();
          } catch (IOException e) {
          e.printStackTrace();
          }

          Element table = doc.body().getElementsByTag("table").first();

          Element thead = table.getElementsByTag("thead").first();

          StringBuilder headBuilder = new StringBuilder();

          for (Element th : thead.getElementsByTag("th")) {
          headBuilder.append(th.text());
          headBuilder.append(" ");
          }

          System.out.println(headBuilder.toString());

          Element tbody = table.getElementsByTag("tbody").first();

          for (Element tr : tbody.getElementsByTag("tr")) {
          StringBuilder rowBuilder = new StringBuilder();

          for (Element td : tr.getElementsByTag("td")) {
          rowBuilder.append(td.text());
          rowBuilder.append(" ");
          }
          System.out.println(rowBuilder.toString());
          }


          The output is :



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 13:50









          Emre SavcıEmre Savcı

          2,0911819




          2,0911819













          • Incredible. Works flawlessly. Just wondering, how did you know the names of things like tbody and tr, td?

            – David
            Nov 25 '18 at 13:54











          • Well, it is just html. If you want to extract data from a web page, just right click inspect and take a look it's html. You find the required information there.

            – Emre Savcı
            Nov 25 '18 at 13:56





















          • Incredible. Works flawlessly. Just wondering, how did you know the names of things like tbody and tr, td?

            – David
            Nov 25 '18 at 13:54











          • Well, it is just html. If you want to extract data from a web page, just right click inspect and take a look it's html. You find the required information there.

            – Emre Savcı
            Nov 25 '18 at 13:56



















          Incredible. Works flawlessly. Just wondering, how did you know the names of things like tbody and tr, td?

          – David
          Nov 25 '18 at 13:54





          Incredible. Works flawlessly. Just wondering, how did you know the names of things like tbody and tr, td?

          – David
          Nov 25 '18 at 13:54













          Well, it is just html. If you want to extract data from a web page, just right click inspect and take a look it's html. You find the required information there.

          – Emre Savcı
          Nov 25 '18 at 13:56







          Well, it is just html. If you want to extract data from a web page, just right click inspect and take a look it's html. You find the required information there.

          – Emre Savcı
          Nov 25 '18 at 13:56




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468012%2fhow-can-i-print-the-contents-of-this-html-table-using-jsoup%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)