2017-12-26 43 views
0

href属性からURLを取得できません。 私はこのコードを使用しますhref属性からURLを取得する方法

Dim url As String = "http://example.com/" 
Dim web As New HtmlWeb() 
Dim doc As HtmlDocument = web.Load(url) 

For Each item As HtmlNode In doc.DocumentNode.SelectNodes("//a/@href") 
    If Not item Is Nothing Then 
     Response.Write(item.OuterHtml) 
    End If 
Next 

しかし、それは動作しません。 href以来

答えて

2

は、あなたがそれらで検索しているとき[]

覚えている属性は、ブラケットを正方形に入る角括弧でそれを配置する必要があり属性です。あなたのケースでは

//a[@href] 

あなたはHasAttributes("href")、最終的には、取得Attributes("href")をチェックし、その後、すべての//aのノードを取得する必要があります。

For Each item As HtmlNode In doc.DocumentNode.SelectNodes("//a") 
    If Not item Is Nothing And item.HasAttributes("href") Then 
     Response.Write(item.Attributes("href").Value) 
    End If 
Next 
0

私はlynda.com からデモビデオを取得するには、このメソッドを使用しますが、それはない作品@Sunil!それは403エラー

HtmlNode videoNode = doc.DocumentNode.SelectSingleNode("//video[@class='player']"); 
       string firstsLink = videoNode.Attributes["data-src"].Value; 
       List<string> secLink = firstsLink.Split(';').ToList(); 
       videoURL = (secLink[index: 0]); 

https://www.lynda.com/mocha-tutorials/mocha-5-Essential-Training/601820-2.html

関連する問題