简体   繁体   中英

Parse table details not having ID or a class name using JSOUP in JAVA

I have two more than two tables in a web page.
They are given below:

  1. <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; float : left">
  2. <table width="100%" border="0" cellspacing="1" cellpadding="2" style="border-collapse : collapse">
  3. <table border="0" cellpadding="0" cellspacing="0" style="border-collapse : collapse">

I need to get the rows and columns of second table which doesn't contain any id or class name. How do i get its details using doc.select(); method

If the table you want to get is always the second you can use ( demo ):

table:nth-of-type(2)

From the documentation of Jsoup selectors:

nth-of-type(an+b) pseudo-class notation represents an element that has an+b-1 siblings with the same expanded element name before it in the document tree, for any zero or positive integer value of n, and has a parent element.

If it's not always the second you should find some attribute values that only your table has and use them in the selector. For example in your case it could be:

table[width=100%][border=0][cellspacing=1][cellpadding=2]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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