我正在尝试从大型 HTML 页面中解析出值,并且正在努力解决如何从两个选择器之间提取文本。这是我的示例 HTML 来说明:
<table class="categories">
<tr class="category">
<td class="categoryTitle">Category #1</td>
<td class="categoryDate">12-1-2012</td>
<td class="categoryFoos">212</td>
</tr>
<tr class="catItem">
<td class="catItemName"><div class="itemName">Category Item #1</div></td>
<td class="catItemColor">Blue</td>
<td class="catItemSprockets">17</td>
</tr>
<tr class="catItem">
<td class="catItemName"><div class="itemName">Category Item #2</div></td>
<td class="catItemColor">Red</td>
<td class="catItemSprockets">454</td>
</tr>
<tr class="catItem">
<td class="catItemName"><div class="itemName">Category Item #3</div></td>
<td class="catItemColor">Purple</td>
<td class="catItemSprockets">11</td>
</tr>
<tr class="category">
<td class="categoryTitle">Category #2</td>
<td class="categoryDate">12-17-2012</td>
<td class="categoryFoos">311</td>
</tr>
<tr class="catItem">
<td class="catItemName"><div class="itemName">Category Item #1</div></td>
<td class="catItemColor">Yellow</td>
<td class="catItemSprockets">73</td>
</tr>
<tr class="catItem">
<td class="catItemName"><div class="itemName">Category Item #2</div></td>
<td class="catItemColor">Red</td>
<td class="catItemSprockets">5</td>
</tr>
<tr class="catItem">
<td class="catItemName"><div class="itemName">Category Item #3</div></td>
<td class="catItemColor">Purple</td>
<td class="catItemSprockets">11</td>
</tr>
</table>
我将如何获取 ICsqWebResponse 并解析每个类别,包括标题、日期和“foos”,以及每个类别中的所有项目作为项目的集合?很清楚我想要得到什么,对象应该是这样的:
Categories = {
Category #1 {
Date: 12-1-2012,
Foos: 212,
Items: [
Category Item #1 {
Color: Blue,
Sprockets: 17
},
Category Item #2 {
Color: Red,
Sprockets: 454
},
... more items ...
]
},
Category #2 {
Date: 12-17-2012,
Sprockets: 311,
Items: [
Category Item #1 {
Color: Yellow,
Sprockets: 73
},
Category Item #2 {
Color: Red,
Sprockets: 5
},
Category Item #3 {
Color: Purple,
Sprockets: 11
}
]
}
}