mzaslam15
mzaslam15

Reputation: 11

Parsing information from HTML to find out the selected option

I am using Java and Jsoup library to parse the text out of html. In the html I have two options called Single and Multiple. Both have a check mark next to them and if the option selected is Single the checkbox is check and the box the Multiple is not checked. I need to find a way using code which option is selected whether it's multiple or single. I truly appreciate your help. Thank you.

Image show options


  <table class="MsoNormalTable" style="border-collapse:collapse;mso-yfti-tbllook:1184;mso-padding-alt:0in 0in 0in 0in" cellspacing="0" cellpadding="0" border="1">
   <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;height:21.0pt">
    <td style="width:36.75pt;border-top:solid windowtext 1.0pt;
    border-left:solid windowtext 1.0pt;border-bottom:none;border-right:none;
    background:#F2F2F2;padding:.75pt .75pt .75pt .75pt;height:21.0pt" width="49">
    <p class="MsoNormal" style="margin-top:0in;margin-right:-6.0pt;
    margin-bottom:0in;margin-left:-6.0pt;margin-bottom:.0001pt;text-align:center;
    vertical-align:baseline" align="center">​​<span style="font-family:&quot;MS Gothic&quot;">☒</span>​&nbsp;&nbsp;</p>
    </td>
    <td style="width:442.5pt;border-top:solid windowtext 1.0pt;
    border-left:none;border-bottom:none;border-right:solid windowtext 1.0pt;
    background:#F2F2F2;padding:.75pt .75pt .75pt .75pt;height:21.0pt" width="590">
    <p class="MsoNormal" style="margin-left:1.5pt;vertical-align:baseline"><span style="font-size:10.0pt">Single&nbsp;</span></p>
    </td>
   </tr>
   <tr style="mso-yfti-irow:1;mso-yfti-lastrow:yes">
    <td style="width:36.75pt;border:none;border-left:solid windowtext 1.0pt;
    background:#F2F2F2;padding:.75pt .75pt .75pt .75pt" width="49">
    <p class="MsoNormal" style="margin-top:0in;margin-right:-6.0pt;
    margin-bottom:0in;margin-left:-6.0pt;margin-bottom:.0001pt;text-align:center;
    vertical-align:baseline" align="center">​​<span style="font-family:&quot;MS Gothic&quot;">☐</span>​&nbsp;</p>
    </td>
    <td style="width:442.5pt;border:none;border-right:solid windowtext 1.0pt;
    background:#F2F2F2;padding:.75pt .75pt .75pt .75pt" width="590">
    <p class="MsoNormal" style="margin-left:1.5pt;vertical-align:baseline"><span style="font-size:10.0pt">Multiple&nbsp;</span></p>
    </td>
   </tr>
  </tbody></table>
  <p class="MsoNormal" style="vertical-align:baseline"><span style="font-size:
  10.0pt;font-family:&quot;Times New Roman&quot;,serif">&nbsp;</span></p>

Upvotes: 0

Views: 103

Answers (1)

legoscia
legoscia

Reputation: 41578

Try this:

Document doc = Jsoup.parse(html);
String selected = doc.select("tr:contains(☒) td:eq(1)").first().text();

selected should then contain the text of the selected option, "Single" or "Multiple".

The tr:contains(☒) selector picks the table row that contains the ☒ symbol, and td:eq(1) then selects the second table cell in that row. (It counts starting at 0, so the first cell is number 0, the second cell is number 1 etc.)

Upvotes: 1

Related Questions