HtmlAgilityPack基本如何获得标题和链接? [英] HtmlAgilityPack basic how to get title and link?
本文介绍了HtmlAgilityPack基本如何获得标题和链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Html
< div class =col>
< a class =video-boxtitle =En son haberhref =http:// ** / en-son-haber>
< span class =title>儿子haber< / span>
< span class =duration> 01:02< / span>< span class =view-count> 9.023< / span>< / a>
< / div>
代码
Dim request2 As HttpWebRequest = WebRequest.Create(http://**.com/)
Dim response2 As HttpWebResponse = request2.GetResponse()
Dim reader2 As StreamReader = New StreamReader(response2.GetResponseStream())
Dim sayfa2 As String = reader2.ReadToEnd()
Dim dokuman2 = New HtmlAgilityPack.HtmlDocument()
dokuman2.LoadHtml(sayfa2 )
Dim getir2 As HtmlAgilityPack.HtmlNodeCollection =dokuman2.DocumentNode.SelectNodes(// div [@ class ='col'])
对于每个节点在getir2
TextBox1 .Text + = node.SelectSingleNode(// a [@ class ='video-box'])。SelectSingleNode(href)。InnerText
Next
我想要获得 link
和 title
in一个 div
但 SelectSingleNode
检索重复值..
如何得到真实。 示例rel =nofollow> http://htmlagilitypack.codeplex.com/wikipage?title=示例,第一个示例显示如何访问属性。
所以在你的情况下
对于每个节点在getir2
dim aTag中,为HtmlAgilityPack.HtmlNode = node。 SelectSingleNode(// a [@ class ='video-box'])
TextBox1.Text + = aTag [href]。value
',标题为
TextBox1。 Text + = aTag [title]。value
Next
Html
<div class="col">
<a class="video-box" title="En son haber" href="http://**/en-son-haber">
<img class="img-responsive" alt="en son haber" src="http://**/thumb/6/9/6/200x120/en-son-haber-49-29.jpg">
<span class="title">En son haber</span>
<span class="duration">01:02</span><span class="view-count">9.023</span></a>
</div>
Code
Dim request2 As HttpWebRequest = WebRequest.Create("http://**.com/")
Dim response2 As HttpWebResponse = request2.GetResponse()
Dim reader2 As StreamReader = New StreamReader(response2.GetResponseStream())
Dim sayfa2 As String = reader2.ReadToEnd()
Dim dokuman2 = New HtmlAgilityPack.HtmlDocument()
dokuman2.LoadHtml(sayfa2)
Dim getir2 As HtmlAgilityPack.HtmlNodeCollection = dokuman2.DocumentNode.SelectNodes("//div[@class='col']")
For Each node In getir2
TextBox1.Text += node.SelectSingleNode("//a[@class='video-box']").SelectSingleNode("href").InnerText
Next
I want get link
and title
in a div
but SelectSingleNode
retrieving duplicate value..
How to get true.
解决方案
If you see the examples page http://htmlagilitypack.codeplex.com/wikipage?title=Examples, the very first example shows how to access attributes..
so in your case
For Each node In getir2
dim aTag as HtmlAgilityPack.HtmlNode = node.SelectSingleNode("//a[@class='video-box']")
TextBox1.Text += aTag["href"].value
'and for the title
TextBox1.Text += aTag["title"].value
Next
这篇关于HtmlAgilityPack基本如何获得标题和链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文