Reputation: 63
I am new to html agility, I tried to get a mp3 link in the source code below:
<div id="fullPlayer">
<script type="text/javascript" src="http://stc.m.nixcdn.com/js/html5-player.0.1.js"></script>
<div class="player">
<div class="hide-html5">
<audio id="audio" controls="controls">
<source src="http://aredir.nixcdn.com/18c5db02a7804db01de320c1d34e5e6d/582c6bb4/NhacCuaTui217/Anh-HoQuynhHuong_3ycwf.mp3" type="audio/mpeg" />
</audio>
</div>
<div id="play" class="play control">
</div>
When I tried, I could not access the "hide-html5" node, but it is ok for the "fullPlayer". Thus, the src attribute is not for image , in this case, it is an audio link. Looking at the structure, the "hide-html5" node is the child node of "fullPlayer", then how could I extract the mp3 link from it? Below is the code I used but failed.
Dim doc As HtmlDocument = New HtmlWeb().Load("http://m.nhaccuatui.com/bai-hat/anh-ho-quynh-huong.hp7uaRRC5ID1.html")
Dim div As HtmlNode = doc.DocumentNode.SelectSingleNode("//div[@class='hide-html5']")
If Not div Is Nothing Then
Dim att As HtmlAttribute = div.Attributes("src")
MsgBox(att.Value)
Else
Msgbox("not accessible")
End if
Does it need any special code to access the child node in html agility?, Please share. Thank you ~
Upvotes: 1
Views: 114
Reputation: 4173
Seems you are trying to get the src
attribute of a div
but he doesn't have one as I see, you need to get the src
attribute of the source element.
The selector for the source could be one of the following:
//div[@id='fullPlayer']//source
//audio[@id='audio']//source
Finding this node and getting his src
attribute should solve the problem.
Upvotes: 1