I'm getting data from a website, this website contains 2 tables
1- warranty date
2- upgrade warranty date
when I select elements by "td" and try to get the start date by sub-string it I get the result as below
2015-01-01
2015-01-01
I want to separate the above 2 dates so that I can use each one alone. I want them to be considered as one line
2015-01-012015-01-01
and then I can sub-string each one alone to use it as I need. I tried to use (.toString()) and then scanner and then sub-string, but it does the sub-string for both example, if my sub-string is for indexes 1,3, the result will be
201
201
but I want it to be
201
2015-01-01
so the second line would be considered as different one ! my code is:
if(tableTitle.contains("Warranty and Service Information:")) {
theElements = ele.select("td");
String contenent1;
contenent1 = theElements.toString();
// this is not the scanner I mentioned above
Scanner sr1 = new Scanner(contenent1);
startDate = contenent1.substring(4, 14);
endDate = contenent1.substring(24, 34);
System.out.println(startDate);
}
and the result is:
2012-07-04
2012-07-04
here are 2 images to show the tables, the table upgrade warranty appears in rare cases only, but when it appears there is a problem to show each result in one line only.
when there is no upgrade table
and here is when the upgrade table appear
and the source codes are:
1- when there is no upgrade table
</td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td><table class="ibm-data-table ibm-alternating" summary="output table" cellpadding="0" cellspacing="0" border="0"><tbody>
<thead>
<tr>
<th scope="col" colspan="3" class="pg2TableSectionTitle">Warranty and Service Information:</th>
</tr>
</thead>
<tr>
<th scope="col">Start Date</th><th scope="col">End Date</th><th scope="col">SDF</th>
</tr>
<tr>
<td>2011-05-11</td><td>2014-06-24</td><td>3PL</td>
</tr>
<tr>
<td colspan="3">
SDF Description:
<span>This product has a 3 year limited warranty and is entitled to CRU (customer replaceable unit) and On-site labor repair service for selected parts. On-site Service is available Monday - Friday, except holidays, with a next business day response objective. A service technician will be scheduled to arrive at the customer's location on the business day after remote problem determination.</span>
</td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td><table class="ibm-data-table ibm-alternating" summary="output table" cellpadding="0" cellspacing="0" border="0"><tbody>
<thead>
<tr>
<th scope="col" colspan="3" class="pg2TableSectionTitle">International Warranty Service Information:</th>
</tr>
</thead>
<tr>
<td><span>
Eligible :
NO</span>
</td>
</tr>
</tbody></table></td>
2- when there is an upgrade table
</td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td><table class="ibm-data-table ibm-alternating" summary="output table" cellpadding="0" cellspacing="0" border="0"><tbody>
<thead>
<tr>
<th scope="col" colspan="3" class="pg2TableSectionTitle">Warranty and Service Information:</th>
</tr>
</thead>
<tr>
<th scope="col">Start Date</th><th scope="col">End Date</th><th scope="col">SDF</th>
</tr>
<tr>
<td>2012-07-04</td><td>2015-07-03</td><td>3XL</td>
</tr>
<tr>
<td colspan="3">
SDF Description:
<span>This product has a 3 year limited warranty and is entitled to CRU (customer replaceable unit) and On-site service. Tier 1 CRUs are customer responsibility, see announcement for details. On-site Service is available Monday - Friday, except holidays, with a next business day response objective.</span>
</td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td><table class="ibm-data-table ibm-alternating" summary="output table" cellpadding="0" cellspacing="0" border="0"><tbody>
<thead>
<tr>
<th scope="col" colspan="3" class="pg2TableSectionTitle">International Warranty Service Information:</th>
</tr>
</thead>
<tr>
<td><span>
Eligible :
YES</span>
</td>
</tr>
<tr>
<td><label for="Below link contains the directory of worldwide contacts.">Below link contains the directory of worldwide contacts.</label></td>
</tr>
<tr>
<td><a href="http://ift.tt/1TIIqZK" target="_blank">http://ift.tt/2a0JkU6;
</td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td><table class="ibm-data-table ibm-alternating" summary="output table" cellpadding="0" cellspacing="0" border="0"><tbody>
<thead>
<tr>
<th scope="col" colspan="3" class="pg2TableSectionTitle">Upgrade Warranty and Service Information:</th>
</tr>
</thead>
<tr>
<th scope="col">Start Date</th><th scope="col">End Date</th><th scope="col">SDF</th>
</tr>
<tr>
<td>2012-07-04</td><td>2015-07-03</td><td>SP4</td>
</tr>
<tr>
<td colspan="3">
SDF Description:
<span>This product has a three year limited warranty which includes a warranty upgrade. This product is entitled to parts and labor and includes on-site repair service. Service is available 7X24 with an 4 hour response objective.</span>
</td>
</tr>
</tbody></table></td>
Here is how the result is shown (with the problem)
And here is how I expect it (just ignore the EMPTY LINE words, I just added to show how I expect the result)
Aucun commentaire:
Enregistrer un commentaire