我正在尝试使用jsoup解析HTML。这是我第一次使用jsoup,并且我也阅读了有关它的一些教程。我已经附上了我正在使用的HTML表格。
import java.io.File;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class test {
public static void main( String[] args ) throws IOException {
File file = new File("Path_location");
Document doc = Jsoup.parse(file, "utf-8");
for (Element table : doc.select("table[id=statisticsTable]")) {
for (Element row : table.select("tbody")) {
Elements tds = row.select("td:not([rowspan])");
System.out.println(tds.get(0).text() + "->" + tds.get(1).text());
}
System.out.println(("table is:" + table));
System.out.println((doc));
}
}
}
我是JSOUP的新手,到目前为止,我的代码没有显示任何异常。我正在使用表ID来查找表。 有什么方法可以获取该值并将其复制到excell。
<table id="statisticsTable" class="table table-bordered table-condensed tablesorter tablesorter-blue" role="grid"><colgroup class="tablesorter-colgroup"><col style="width: 31.4%;"><col style="width: 5.4%;"><col style="width: 2.3%;"><col style="width: 4.3%;"><col style="width: 5.2%;"><col style="width: 3.7%;"><col style="width: 3.7%;"><col style="width: 5.2%;"><col style="width: 5.2%;"><col style="width: 5.2%;"><col style="width: 6.3%;"><col style="width: 5.2%;"><col style="width: 3.4%;"></colgroup>
<thead><tr class="tablesorter-no-sort tablesorter-headerRow" role="row"><th data-sorter="false" colspan="1" data-column="0" class="tablesorter-header sorter-false tablesorter-headerUnSorted" scope="col" role="columnheader" aria-disabled="true" unselectable="on" aria-sort="none" style="user-select: none;"><div class="tablesorter-header-inner">Requests</div></th><th data-sorter="false" colspan="3" data-column="1" class="tablesorter-header sorter-false tablesorter-headerUnSorted" scope="col" role="columnheader" aria-disabled="true" unselectable="on" aria-sort="none" style="user-select: none;"><div class="tablesorter-header-inner">Executions</div></th><th data-sorter="false" colspan="7" data-column="4" class="tablesorter-header sorter-false tablesorter-headerUnSorted" scope="col" role="columnheader" aria-disabled="true" unselectable="on" aria-sort="none" style="user-select: none;"><div class="tablesorter-header-inner">Response Times (ms)</div></th><th data-sorter="false" colspan="2" data-column="11" class="tablesorter-header sorter-false tablesorter-headerUnSorted" scope="col" role="columnheader" aria-disabled="true" unselectable="on" aria-sort="none" style="user-select: none;"><div class="tablesorter-header-inner">Network (KB/sec)</div></th></tr><tr role="row" class="tablesorter-headerRow"><th data-column="0" class="tablesorter-header tablesorter-headerAsc" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="ascending" aria-label="Label: Ascending sort applied, activate to apply a descending sort" style="user-select: none;"><div class="tablesorter-header-inner">Label</div></th><th data-column="1" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="#Samples: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">#Samples</div></th><th data-column="2" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="KO: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">KO</div></th><th data-column="3" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="Error %: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">Error %</div></th><th data-column="4" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="Average: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">Average</div></th><th data-column="5" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="Min: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">Min</div></th><th data-column="6" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="Max: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">Max</div></th><th data-column="7" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="90th pct: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">90th pct</div></th><th data-column="8" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="95th pct: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">95th pct</div></th><th data-column="9" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="99th pct: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">99th pct</div></th><th data-column="10" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="Throughput: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">Throughput</div></th><th data-column="11" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="Received: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">Received</div></th><th data-column="12" class="tablesorter-header tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="false" aria-controls="statisticsTable" unselectable="on" aria-sort="none" aria-label="Sent: No sort applied, activate to apply an ascending sort" style="user-select: none;"><div class="tablesorter-header-inner">Sent</div></th></tr></thead><tbody class="tablesorter-no-sort"><tr role="row"><td>Total</td><td>3640</td><td>10</td><td>0.27%</td><td>3639.93</td><td>13</td><td>538740</td><td>10765.80</td><td>12825.80</td><td>20110.16</td><td>1.77</td><td>372.06</td><td>2.13</td></tr></tbody><tbody aria-live="polite" aria-relevant="all"><tr role="row" class="odd"><td>http://10.0.70.18:8443/api/current-user</td><td>10</td><td>0</td><td>0.00%</td><td>43.80</td><td>31</td><td>59</td><td>58.70</td><td>59.00</td><td>59.00</td><td>75.76</td><td>45.20</td><td>75.91</td></tr><tr role="row" class="even"><td>http://10.0.70.18:8443/api/drop-down-options/case-type</td><td>10</td><td>0</td><td>0.00%</td><td>53.10</td><td>41</td><td>72</td><td>71.80</td><td>72.00</td><td>72.00</td><td>87.72</td><td>45.14</td><td>89.18</td></tr><tr role="row" class="odd"><td>http://10.0.70.18:8443/api/drop-down-options/dash-brand</td><td>10</td><td>0</td><td>0.00%</td><td>77.30</td><td>50</td><td>102</td><td>102.00</td><td>102.00</td><td>102.00</td><td>61.35</td><td>548.97</td><td>62.43</td></tr><tr role="row" class="even"><td>http://10.0.70.18:8443/api/user-preferences</td><td>10</td><td>0</td><td>0.00%</td><td>70.80</td><td>48</td><td>104</td><td>102.90</td><td>104.00</td><td>104.00</td><td>71.43</td><td>23.30</td><td>71.85</td></tr><tr role="row" class="odd"><td>http://10.0.70.18:8443/assets/componentsConf/charts.json</td><td>10</td><td>10</td><td>100.00%</td><td>23.60</td><td>19</td><td>35</td><td>34.20</td><td>35.00</td><td>35.00</td><td>119.05</td><td>40.79</td><td>43.13</td></tr><tr role="row" class="even"><td>http://10.0.70.18:8443/assets/componentsConf/highcharts.json</td><td>10</td><td>0</td><td>0.00%</td><td>20.40</td><td>13</td><td>27</td><td>27.00</td><td>27.00</td><td>27.00</td><td>126.58</td><td>152.67</td><td>46.36</td></tr><tr role="row" class="odd"><td>http://10.0.70.18:8443/assets/componentsConf/widget.json</td><td>10</td><td>0</td><td>0.00%</td><td>20.80</td><td>14</td><td>26</td><td>26.00</td><td>26.00</td><td>26.00</td><td>153.85</td><td>125.30</td><td>55.74</td></tr><tr role="row" class="even"><td>http://10.0.70.18:8443/translations/en.json</td><td>10</td><td>0</td><td>0.00%</td><td>46.30</td><td>25</td><td>71</td><td>70.50</td><td>71.00</td><td>71.00</td><td>138.89</td><td>320.37</td><td>48.56</td></tr><tr role="row" class="odd"><td>Case Export 1 year - All</td><td>10</td><td>0</td><td>0.00%</td><td>35286.20</td><td>32514</td><td>36517</td><td>36504.00</td><td>36517.00</td><td>36517.00</td><td>0.26</td><td>1343.59</td><td>0.34</td></tr><tr role="row" class="even"><td>Case Export 2 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>1839.20</td><td>308</td><td>2525</td><td>2524.10</td><td>2525.00</td><td>2525.00</td><td>0.32</td><td>57.81</td><td>0.42</td></tr><tr role="row" class="odd"><td>Case Export 3 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>567.70</td><td>507</td><td>611</td><td>610.80</td><td>611.00</td><td>611.00</td><td>0.60</td><td>161.33</td><td>0.78</td></tr><tr role="row" class="even"><td>Case Export 5 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>776.60</td><td>443</td><td>974</td><td>968.80</td><td>974.00</td><td>974.00</td><td>1.14</td><td>485.73</td><td>1.50</td></tr><tr role="row" class="odd"><td>Case Search 1 year - All</td><td>10</td><td>0</td><td>0.00%</td><td>10513.90</td><td>8694</td><td>11037</td><td>11036.30</td><td>11037.00</td><td>11037.00</td><td>0.90</td><td>1.03</td><td>1.19</td></tr><tr role="row" class="even"><td>Case Search 2 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>979.80</td><td>197</td><td>3124</td><td>2996.00</td><td>3124.00</td><td>3124.00</td><td>0.30</td><td>0.31</td><td>0.39</td></tr><tr role="row" class="odd"><td>Case Search 3 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>761.60</td><td>268</td><td>1011</td><td>1010.80</td><td>1011.00</td><td>1011.00</td><td>0.58</td><td>0.60</td><td>0.77</td></tr><tr role="row" class="even"><td>Case Search 5 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>1255.00</td><td>442</td><td>1665</td><td>1664.30</td><td>1665.00</td><td>1665.00</td><td>1.02</td><td>1.06</td><td>1.35</td></tr><tr role="row" class="odd"><td>Case Search and Export 1 year - All</td><td>10</td><td>0</td><td>0.00%</td><td>45800.10</td><td>41208</td><td>47554</td><td>47540.30</td><td>47554.00</td><td>47554.00</td><td>0.21</td><td>1097.93</td><td>0.55</td></tr><tr role="row" class="even"><td>Case Search and Export 2 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>2819.00</td><td>505</td><td>5606</td><td>5480.30</td><td>5606.00</td><td>5606.00</td><td>0.29</td><td>52.83</td><td>0.77</td></tr><tr role="row" class="odd"><td>Case Search and Export 3 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>1329.30</td><td>775</td><td>1614</td><td>1610.20</td><td>1614.00</td><td>1614.00</td><td>0.56</td><td>152.75</td><td>1.49</td></tr><tr role="row" class="even"><td>Case Search and Export 5 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>2031.60</td><td>893</td><td>2632</td><td>2627.50</td><td>2632.00</td><td>2632.00</td><td>0.96</td><td>409.47</td><td>2.53</td></tr><tr role="row" class="odd"><td>Element Export 1 year - All</td><td>10</td><td>0</td><td>0.00%</td><td>17554.50</td><td>16441</td><td>19370</td><td>19345.00</td><td>19370.00</td><td>19370.00</td><td>0.52</td><td>10453.41</td><td>0.67</td></tr><tr role="row" class="even"><td>Element Export 2 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>1637.40</td><td>296</td><td>2263</td><td>2262.90</td><td>2263.00</td><td>2263.00</td><td>0.37</td><td>194.48</td><td>0.48</td></tr><tr role="row" class="odd"><td>Element Export 3 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>479.40</td><td>322</td><td>572</td><td>571.10</td><td>572.00</td><td>572.00</td><td>0.61</td><td>323.80</td><td>0.81</td></tr><tr role="row" class="even"><td>Element Export 5 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>318.60</td><td>289</td><td>366</td><td>363.40</td><td>366.00</td><td>366.00</td><td>1.21</td><td>645.87</td><td>1.61</td></tr><tr role="row" class="odd"><td>Element Search 1 year - All</td><td>10</td><td>0</td><td>0.00%</td><td>614.90</td><td>68</td><td>3474</td><td>3334.30</td><td>3474.00</td><td>3474.00</td><td>1.55</td><td>4.95</td><td>2.04</td></tr><tr role="row" class="even"><td>Element Search 2 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>1108.10</td><td>93</td><td>1600</td><td>1599.80</td><td>1600.00</td><td>1600.00</td><td>0.35</td><td>1.13</td><td>0.47</td></tr><tr role="row" class="odd"><td>Element Search 3 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>110.60</td><td>90</td><td>149</td><td>147.30</td><td>149.00</td><td>149.00</td><td>0.61</td><td>2.00</td><td>0.83</td></tr><tr role="row" class="even"><td>Element Search 5 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>88.20</td><td>57</td><td>106</td><td>105.80</td><td>106.00</td><td>106.00</td><td>1.25</td><td>4.07</td><td>1.68</td></tr><tr role="row" class="odd"><td>Element Search and Export 1 year - All</td><td>10</td><td>0</td><td>0.00%</td><td>18169.40</td><td>16511</td><td>22844</td><td>22679.30</td><td>22844.00</td><td>22844.00</td><td>0.44</td><td>8869.71</td><td>1.14</td></tr><tr role="row" class="even"><td>Element Search and Export 2 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>2745.50</td><td>401</td><td>3860</td><td>3860.00</td><td>3860.00</td><td>3860.00</td><td>0.35</td><td>184.88</td><td>0.92</td></tr><tr role="row" class="odd"><td>Element Search and Export 3 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>590.00</td><td>420</td><td>705</td><td>704.90</td><td>705.00</td><td>705.00</td><td>0.60</td><td>322.87</td><td>1.61</td></tr><tr role="row" class="even"><td>Element Search and Export 5 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>406.80</td><td>353</td><td>439</td><td>438.20</td><td>439.00</td><td>439.00</td><td>1.20</td><td>641.56</td><td>3.20</td></tr><tr role="row" class="odd"><td>Finding Search and Export 1 year - All</td><td>10</td><td>0</td><td>0.00%</td><td>556360.70</td><td>544933</td><td>578583</td><td>578581.00</td><td>578583.00</td><td>578583.00</td><td>0.02</td><td>747.00</td><td>0.04</td></tr><tr role="row" class="even"><td>Finding Search and Export 2 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>7015.80</td><td>1219</td><td>9601</td><td>9594.90</td><td>9601.00</td><td>9601.00</td><td>0.38</td><td>211.75</td><td>0.96</td></tr><tr role="row" class="odd"><td>Finding Search and Export 3 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>6375.30</td><td>1700</td><td>8451</td><td>8446.50</td><td>8451.00</td><td>8451.00</td><td>0.56</td><td>741.92</td><td>1.44</td></tr><tr role="row" class="even"><td>Finding Search and Export 5 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>13384.30</td><td>7947</td><td>15865</td><td>15863.70</td><td>15865.00</td><td>15865.00</td><td>0.63</td><td>1677.85</td><td>1.60</td></tr><tr role="row" class="odd"><td>Findings Export 1 year - All</td><td>10</td><td>0</td><td>0.00%</td><td>516438.20</td><td>505086</td><td>538740</td><td>538715.00</td><td>538740.00</td><td>538740.00</td><td>0.02</td><td>802.56</td><td>0.02</td></tr><tr role="row" class="even"><td>Findings Export 2 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>3505.30</td><td>660</td><td>4744</td><td>4744.00</td><td>4744.00</td><td>4744.00</td><td>0.46</td><td>258.49</td><td>0.58</td></tr><tr role="row" class="odd"><td>Findings Export 3 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>5496.90</td><td>1164</td><td>7400</td><td>7399.10</td><td>7400.00</td><td>7400.00</td><td>0.60</td><td>787.54</td><td>0.76</td></tr><tr role="row" class="even"><td>Findings Export 5 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>12843.80</td><td>7376</td><td>15336</td><td>15334.70</td><td>15336.00</td><td>15336.00</td><td>0.65</td><td>1733.93</td><td>0.82</td></tr><tr role="row" class="odd"><td>Findings Search 1 year - All</td><td>10</td><td>0</td><td>0.00%</td><td>39922.50</td><td>39823</td><td>40099</td><td>40098.40</td><td>40099.00</td><td>40099.00</td><td>0.25</td><td>0.47</td><td>0.32</td></tr><tr role="row" class="even"><td>Findings Search 2 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>3510.50</td><td>559</td><td>4890</td><td>4887.20</td><td>4890.00</td><td>4890.00</td><td>0.39</td><td>0.96</td><td>0.50</td></tr><tr role="row" class="odd"><td>Findings Search 3 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>878.40</td><td>519</td><td>1061</td><td>1056.90</td><td>1061.00</td><td>1061.00</td><td>0.61</td><td>1.51</td><td>0.78</td></tr><tr role="row" class="even"><td>Findings Search 5 years - HDFC</td><td>10</td><td>0</td><td>0.00%</td><td>540.50</td><td>523</td><td>571</td><td>568.60</td><td>571.00</td><td>571.00</td><td>1.18</td><td>2.93</td><td>1.51</td></tr><tr role="row" class="odd"><td>Load Login Page</td><td>10</td><td>10</td><td>100.00%</td><td>969.70</td><td>634</td><td>1330</td><td>1327.80</td><td>1330.00</td><td>1330.00</td><td>6.52</td><td>3382.77</td><td>22.41</td></tr><tr role="row" class="even"><td>Login and Dashboard</td><td>10</td><td>0</td><td>0.00%</td><td>823.90</td><td>791</td><td>867</td><td>864.60</td><td>867.00</td><td>867.00</td><td>11.22</td><td>131.99</td><td>51.85</td></tr><tr role="row" class="odd"><td>Login Page</td><td>10</td><td>0</td><td>0.00%</td><td>858.60</td><td>506</td><td>1205</td><td>1204.70</td><td>1205.00</td><td>1205.00</td><td>7.50</td><td>3855.28</td><td>14.97</td></tr><tr role="row" class="even"><td>Login User</td><td>10</td><td>0</td><td>0.00%</td><td>578.90</td><td>541</td><td>616</td><td>614.20</td><td>616.00</td><td>616.00</td><td>14.99</td><td>20.61</td><td>8.67</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 2 Years, caseType : Advance Fee Fraud, widgetName : ATTACK_STATUS_OVERVIEW</td><td>10</td><td>0</td><td>0.00%</td><td>4418.00</td><td>4118</td><td>4691</td><td>4680.90</td><td>4691.00</td><td>4691.00</td><td>2.13</td><td>1.10</td><td>2.60</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 2 Years, caseType : Advance Fee Fraud, widgetName : ATTACK_TRENDING_CASES_N_ELEMENTS</td><td>10</td><td>0</td><td>0.00%</td><td>2078.40</td><td>1867</td><td>2218</td><td>2209.50</td><td>2218.00</td><td>2218.00</td><td>4.50</td><td>3.00</td><td>5.53</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 2 Years, caseType : Advance Fee Fraud, widgetName : SHUTDOWN_MEDIAN</td><td>10</td><td>0</td><td>0.00%</td><td>1037.90</td><td>413</td><td>1528</td><td>1527.30</td><td>1528.00</td><td>1528.00</td><td>2.16</td><td>1.05</td><td>2.62</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 2 Years, caseType : All, widgetName : ATTACK_STATUS_OVERVIEW</td><td>10</td><td>0</td><td>0.00%</td><td>1217.60</td><td>1094</td><td>1474</td><td>1461.20</td><td>1474.00</td><td>1474.00</td><td>5.77</td><td>3.00</td><td>6.95</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 2 Years, caseType : All, widgetName : ATTACK_TRENDING_CASES_N_ELEMENTS</td><td>10</td><td>0</td><td>0.00%</td><td>1011.00</td><td>900</td><td>1185</td><td>1181.00</td><td>1185.00</td><td>1185.00</td><td>7.83</td><td>6.36</td><td>9.51</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 2 Years, caseType : All, widgetName : CURRENT_ACTIVITY_ONLINE_ELEMENTS_SUMMARY</td><td>60</td><td>0</td><td>0.00%</td><td>292.83</td><td>172</td><td>341</td><td>324.70</td><td>326.00</td><td>341.00</td><td>4.87</td><td>3.17</td><td>5.95</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 2 Years, caseType : All, widgetName : HOSTING_COUNTRIES</td><td>60</td><td>0</td><td>0.00%</td><td>13843.70</td><td>10299</td><td>28537</td><td>15257.30</td><td>15443.10</td><td>28537.00</td><td>0.51</td><td>0.62</td><td>0.61</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 2 Years, caseType : All, widgetName : SHUTDOWN_MEDIAN</td><td>10</td><td>0</td><td>0.00%</td><td>1462.90</td><td>807</td><td>1936</td><td>1921.90</td><td>1936.00</td><td>1936.00</td><td>1.79</td><td>0.98</td><td>2.14</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 2 Years, caseType : Brand Abuse, widgetName : ATTACK_STATUS_OVERVIEW</td><td>10</td><td>0</td><td>0.00%</td><td>774.70</td><td>684</td><td>894</td><td>892.30</td><td>894.00</td><td>894.00</td><td>11.17</td><td>5.79</td><td>13.55</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 2 Years, caseType : Brand Abuse, widgetName : ATTACK_TRENDING_CASES_N_ELEMENTS</td><td>10</td><td>0</td><td>0.00%</td><td>706.90</td><td>631</td><td>778</td><td>777.10</td><td>778.00</td><td>778.00</td><td>12.53</td><td>9.81</td><td>15.32</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 2 Years, caseType : Brand Abuse, widgetName : SHUTDOWN_MEDIAN</td><td>10</td><td>0</td><td>0.00%</td><td>1164.70</td><td>549</td><td>1671</td><td>1660.30</td><td>1671.00</td><td>1671.00</td><td>2.13</td><td>1.16</td><td>2.57</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 2 Years, caseType : Phishing, widgetName : ATTACK_STATUS_OVERVIEW</td><td>10</td><td>0</td><td>0.00%</td><td>886.40</td><td>812</td><td>952</td><td>949.30</td><td>952.00</td><td>952.00</td><td>8.73</td><td>4.53</td><td>10.56</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 2 Years, caseType : Phishing, widgetName : ATTACK_TRENDING_CASES_N_ELEMENTS</td><td>10</td><td>0</td><td>0.00%</td><td>810.40</td><td>751</td><td>909</td><td>905.00</td><td>909.00</td><td>909.00</td><td>9.96</td><td>8.09</td><td>12.15</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 2 Years, caseType : Phishing, widgetName : SHUTDOWN_MEDIAN</td><td>10</td><td>0</td><td>0.00%</td><td>1591.60</td><td>733</td><td>2336</td><td>2334.50</td><td>2336.00</td><td>2336.00</td><td>2.66</td><td>1.46</td><td>3.20</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 2 Years, caseType : Trojan, widgetName : ATTACK_STATUS_OVERVIEW</td><td>10</td><td>0</td><td>0.00%</td><td>758.80</td><td>736</td><td>806</td><td>805.10</td><td>806.00</td><td>806.00</td><td>9.95</td><td>5.16</td><td>12.02</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 2 Years, caseType : Trojan, widgetName : ATTACK_TRENDING_CASES_N_ELEMENTS</td><td>10</td><td>0</td><td>0.00%</td><td>524.70</td><td>461</td><td>618</td><td>613.30</td><td>618.00</td><td>618.00</td><td>11.68</td><td>9.05</td><td>14.23</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 2 Years, caseType : Trojan, widgetName : SHUTDOWN_MEDIAN</td><td>10</td><td>0</td><td>0.00%</td><td>1557.30</td><td>585</td><td>1940</td><td>1938.30</td><td>1940.00</td><td>1940.00</td><td>2.77</td><td>1.52</td><td>3.33</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 2 Years, caseType : Vishing, widgetName : ATTACK_STATUS_OVERVIEW</td><td>10</td><td>0</td><td>0.00%</td><td>626.60</td><td>530</td><td>713</td><td>710.20</td><td>713.00</td><td>713.00</td><td>10.73</td><td>5.53</td><td>12.97</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 2 Years, caseType : Vishing, widgetName : ATTACK_TRENDING_CASES_N_ELEMENTS</td><td>10</td><td>0</td><td>0.00%</td><td>296.50</td><td>272</td><td>329</td><td>328.40</td><td>329.00</td><td>329.00</td><td>15.06</td><td>10.15</td><td>18.35</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 2 Years, caseType : Vishing, widgetName : SHUTDOWN_MEDIAN</td><td>10</td><td>0</td><td>0.00%</td><td>1714.00</td><td>667</td><td>2346</td><td>2328.90</td><td>2346.00</td><td>2346.00</td><td>2.10</td><td>1.02</td><td>2.52</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 3 Years, caseType : Advance Fee Fraud, widgetName : ATTACK_STATUS_OVERVIEW</td><td>10</td><td>0</td><td>0.00%</td><td>4764.70</td><td>4501</td><td>5013</td><td>5006.40</td><td>5013.00</td><td>5013.00</td><td>1.96</td><td>1.01</td><td>2.39</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 3 Years, caseType : Advance Fee Fraud, widgetName : ATTACK_TRENDING_CASES_N_ELEMENTS</td><td>10</td><td>0</td><td>0.00%</td><td>2001.80</td><td>1861</td><td>2115</td><td>2115.00</td><td>2115.00</td><td>2115.00</td><td>4.63</td><td>3.36</td><td>5.68</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 3 Years, caseType : Advance Fee Fraud, widgetName : SHUTDOWN_MEDIAN</td><td>10</td><td>0</td><td>0.00%</td><td>1220.10</td><td>670</td><td>1967</td><td>1964.50</td><td>1967.00</td><td>1967.00</td><td>1.91</td><td>0.93</td><td>2.31</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 3 Years, caseType : All, widgetName : ATTACK_STATUS_OVERVIEW</td><td>10</td><td>0</td><td>0.00%</td><td>1295.30</td><td>1075</td><td>1627</td><td>1601.20</td><td>1627.00</td><td>1627.00</td><td>5.87</td><td>3.06</td><td>7.08</td></tr><tr role="row" class="odd"><td>Widget Filer - day : Customized 3 Years, caseType : All, widgetName : ATTACK_TRENDING_CASES_N_ELEMENTS</td><td>10</td><td>0</td><td>0.00%</td><td>1522.20</td><td>1317</td><td>1814</td><td>1810.50</td><td>1814.00</td><td>1814.00</td><td>5.30</td><td>5.01</td><td>6.44</td></tr><tr role="row" class="even"><td>Widget Filer - day : Customized 3 Years, caseType : All, widgetName : CURRENT_ACTIVITY_ONLINE_ELEMENTS_SUMMARY</td><td>60</td><td>0</td><td>0.00%</td><td>416.77</td><td>387</td><td>460</td><td>432.80</td><td>438.95</td><td>460.00</td><td>4.58</td><td>2.98</td><td>5.60</td></tr></tbody></table>
谢谢
答案 0 :(得分:0)
您正在选择并迭代多个tbody
。如果要遍历每一行,则需要选择每一个tr
。固定代码:
public static void main(String[] args) throws IOException {
File file = new File("table.html");
Document doc = Jsoup.parse(file, "utf-8");
for (Element table : doc.select("table[id=statisticsTable]")) {
Elements rows = table.select("tbody tr");
System.out.println("found rows: " + rows.size());
rows.remove(rows.first()); // Removing first row: "Total->3640"
for (Element row : rows) {
Elements tds = row.select("td:not([rowspan])");
System.out.println(tds.get(0).text() + "->" + tds.get(1).text());
}
}
}
如果您需要有关创建excel文件(不是简单的CSV)的帮助,可以在这里找到我使用JExcel的充分解释的示例:Importing URLs for JSOUP to Scrape via Spreadsheet