[英]How can I get specific links in a class?
I have a html structure like this: 我有这样的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">
There are a couple div class="YazarDetayTarih_Conteiner"> . 有一对div class =“ YazarDetayTarih_Conteiner”>。 and I want to get these href links.
我想获取这些href链接。 Currently when I write like
目前,当我写像
HtmlElementCollection col = web.Document.GetElementsByTagName("a");
foreach (HtmlElement el in col)
{
link = el.GetAttribute("href");
}
It gives all a href links at the page. 它提供了页面上的所有href链接。 How can I specifically take only href which belongs to \\a class="haberlink"
我怎样才能只使用属于\\ a class =“ haberlink”的href
edit : I couldnt make it work. 编辑:我无法使其工作。 after I try richTextBox1.Text += el.GetAttribute("class") it gives blank page.
在我尝试richTextBox1.Text + = el.GetAttribute(“ class”)之后,它给出了空白页。
while using nodes we can do like SelectNodes("//*[contains(@class,'haberlink')]"); 在使用节点时,我们可以像SelectNodes(“ // * [contains(@ class,'haberlink')]”) is there any way to do this?
有什么办法吗?
Inside your foreach loop, skip the ones not having the desired class: 在您的foreach循环中,跳过那些没有所需类的类:
if(el.GetAttribute("class") != "haberlink")
continue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.