My HTML Code Is
<tr>
<td colspan="8" class="text">
<B>Total</B>:
</td>
<td class="text">
<b> 1 GB</b>
</td>
<td class="text">
<b> 1.8 GB</b>
</td>
</tr>
Now i want to get the data inside td tag having class="text".
In python i would have done this:
historySoup = BeautifulSoup(html)
table = historySoup.find('td', attrs={
"colspan": "8",
"class": "text"
}).parent
tds = table.findAll('td')
puts(tds[1].text)
puts(tds[2].text)
But I'm stuck with AngelSharp.I tried this :
var parser = new HtmlParser();
var document = parser.Parse(myhtml);
var blueListItemsCssSelector = document.QuerySelectorAll("td[colspan = '3']");
foreach (var item in blueListItemsCssSelector)
{
item.GetElementsByClassName("text");
var x = item.Text();
}
But I am just getting total as text in x and then the loop ends.Any idea how access the inner td tags of tr and store their text in a list or array?Also it takes time parsing any other method which is faster because my html contains more than 200 td tags
Hey you were doing it right ! In your C# code just add this
List<string> dataList = new List<string>();
foreach (var item in blueListItemsCssSelector)
{
var x = item.NextElementSibling;
dataList.Add(x.Text());
var y = x.NextElementSibling;
dataList.Add(y.Text());
}
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.