我有这样的html结构:
<div class="YazarDetayTarih_Conteiner">
<div class="YazarDetayTarih FL">30.Mart.2013, Cumartesi</div>
<div class="YazarDetayBaslik FL">
<a class="haberlink" href="http://www.hurriyet.com.tr/yazarlar/22928436.asp">Böyle özür olmaz Serdar Ortaç</a>
</div>
</div>
<div class="YazarDetayTarih_Conteiner">
<div class="YazarDetayTarih_Conteiner">
有一对div class =“ YazarDetayTarih_Conteiner”>。我想获取这些href链接。目前,当我写像
HtmlElementCollection col = web.Document.GetElementsByTagName("a");
foreach (HtmlElement el in col)
{
link = el.GetAttribute("href");
}
它提供了页面上的所有href链接。我该如何专门只提取属于\ a class =“ haberlink”的href
编辑:我无法使其工作。在我尝试richTextBox1.Text + = el.GetAttribute(“ class”)之后,它给出了空白页。
在使用节点时,我们可以像SelectNodes(“ // * [contains(@ class,'haberlink')]”)有什么办法吗?
在您的foreach循环中,跳过那些没有所需类的类:
if(el.GetAttribute("class") != "haberlink")
continue;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句