如何在< a>中获得第二个href链接使用vb.net标记 [英] How do I get the second href link in the <a> tag using vb.net

查看:73
本文介绍了如何在< a>中获得第二个href链接使用vb.net标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML代码

 <   div     id   =  dl_link    style   =  display:block; >  
< a href = / get?video_id = KMU0tzLwhbE& h = -1& r = -1.1 style = < span class =code-keyword> display:none > 下载 < / a >
< a href = / get?ab = 128& video_id = KMU0tzLwhbE& h = f25a5baaa46941a22d89c09ee679a305& r = 1405000885751.1521813114 < span class =code-keyword>> 下载 < / a >





所以我想要检索HTML代码中的第二个href链接(/get?ab=128&video_id=KMU0tzLwhbE&h=f25a5baaa46941a22d89c09ee679a305&r=1405000885751.1521813114)



目前我拥有的是这个



  Dim  link_label 作为 HtmlElement = WebBrowser 1.Document.GetElementById(  dl_link

Dim linka As HtmlElement = link_label.GetElementsByTagName( A)( 0
Dim link 作为 字符串 = linka.GetAttribute( HREF





但是只获得第一个href链接这不是我想要的,所以如何获得第二个?

解决方案

这不是最佳选择,但您可以尝试:



Dim linka As HtmlElement = link_label.GetElementsByTagName(A)(1)


如果代码不断更改不同位置,我该怎么办?网页?那我该怎么办?仅当该行文本每次都保留在同一位置时,才将0更改为1。 :(

HTML Code

<div id="dl_link" style="display: block;">
<a href="/get?video_id=KMU0tzLwhbE&h=-1&r=-1.1" style="display:none">Download</a>
<a href="/get?ab=128&video_id=KMU0tzLwhbE&h=f25a5baaa46941a22d89c09ee679a305&r=1405000885751.1521813114">Download</a>



So I want to retrieve the second href link in the HTML code ("/get?ab=128&video_id=KMU0tzLwhbE&h=f25a5baaa46941a22d89c09ee679a305&r=1405000885751.1521813114")

Currently what I have is this

Dim link_label As HtmlElement = WebBrowser1.Document.GetElementById("dl_link")

Dim linka As HtmlElement = link_label.GetElementsByTagName("A")(0)    
Dim link As String = linka.GetAttribute("HREF")



but that only gets the first href link which is not what I want, so how do I get the second one?

解决方案

This is not optimal, but you could try:

Dim linka As HtmlElement = link_label.GetElementsByTagName("A")(1)


What would I have to do if the code keeps changing places on different pages? How would I do it then? Changing the 0 to a 1 only works if that line of text stays in the same place each time. :(


这篇关于如何在&lt; a&gt;中获得第二个href链接使用vb.net标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆