10 Replies - 665 Views - Last Post: 11 July 2014 - 09:49 AM Rate Topic: -----

#1 WombatCombat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-July 14

How do I get the second href link in the <a> tag using vb.net

Posted 10 July 2014 - 07:15 AM

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 which is : "/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?

Is This A Good Question/Topic? 0
  • +

Replies To: How do I get the second href link in the <a> tag using vb.net

#2 Sheepings  Icon User is offline

  • D.I.C Addict

Reputation: 72
  • View blog
  • Posts: 571
  • Joined: 05-December 13

Re: How do I get the second href link in the <a> tag using vb.net

Posted 10 July 2014 - 01:32 PM

Try this WebBrowser Topic. The part of interest
Dim myElement = (From MainElement As HtmlElement In WebBrowserLogin.document.GetElementsByTagName("a")
                                     Where MainElement.GetAttribute("href") = "http://"
                                     Select MainElement)
If myElement(0) IsNot Nothing Then
    myElement(0).InnerText = MyString
End If
You will need to edit to your own requirements.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3729
  • View blog
  • Posts: 13,021
  • Joined: 12-December 12

Re: How do I get the second href link in the <a> tag using vb.net

Posted 10 July 2014 - 01:37 PM

If you want the second element then use (1) rather than (0).
Was This Post Helpful? 1
  • +
  • -

#4 Sheepings  Icon User is offline

  • D.I.C Addict

Reputation: 72
  • View blog
  • Posts: 571
  • Joined: 05-December 13

Re: How do I get the second href link in the <a> tag using vb.net

Posted 10 July 2014 - 01:45 PM

Yes, just change the integer to whatever static number that represents the html link in code. It would be better practice to not guess that will be the link you will want to select from the browser and check additional parameters to see if the link contains ' /get?ab= ' and loop through only the ones containing that text to be more precise; thus returning only download links.
Was This Post Helpful? 0
  • +
  • -

#5 WombatCombat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-July 14

Re: How do I get the second href link in the <a> tag using vb.net

Posted 11 July 2014 - 06:21 AM

Yes the value is not static, I just realized this.. So how would I go along getting the link if I do not know which line it will appear in?

View PostSheepings, on 10 July 2014 - 01:45 PM, said:

Yes, just change the integer to whatever static number that represents the html link in code. It would be better practice to not guess that will be the link you will want to select from the browser and check additional parameters to see if the link contains ' /get?ab= ' and loop through only the ones containing that text to be more precise; thus returning only download links.


I tried to do what you have written above and I changed it to my own code requirements but I do not understand what you set "MyString" to in this line as you have not declared it before
myElement(0).InnerText = MyString

Was This Post Helpful? 0
  • +
  • -

#6 Sheepings  Icon User is offline

  • D.I.C Addict

Reputation: 72
  • View blog
  • Posts: 571
  • Joined: 05-December 13

Re: How do I get the second href link in the <a> tag using vb.net

Posted 11 July 2014 - 07:08 AM

If myElement(1).InnerText has a html link, then this will be a string of text. So declare your ' MyString ' As a String - Dim MyString As String. I would also advise, if you are making a video downloader or something, that you at this point with this URI, to pass it to a WebClient to download the file. Assuming of course this is what you might be doing? I'm just guessing since you haven't said why you need this code.

I'll just point out so you are clear, now you have the element link, you can do what you want with it by using myElement(1).InnerText or myElement(2).InnerText etc... Let me know if you have any other questions.
Was This Post Helpful? 0
  • +
  • -

#7 WombatCombat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-July 14

Re: How do I get the second href link in the <a> tag using vb.net

Posted 11 July 2014 - 07:22 AM

View PostSheepings, on 11 July 2014 - 07:08 AM, said:

If myElement(1).InnerText has a html link, then this will be a string of text. So declare your ' MyString ' As a String - Dim MyString As String. I would also advise, if you are making a video downloader or something, that you at this point with this URI, to pass it to a WebClient to download the file. Assuming of course this is what you might be doing? I'm just guessing since you haven't said why you need this code.

I'll just point out so you are clear, now you have the element link, you can do what you want with it by using myElement(1).InnerText or myElement(2).InnerText etc... Let me know if you have any other questions.


I still don't quite follow, so this is the HTML code of the web page
Posted Image

Currently the "/get?ab" link is the third one, so does that mean it would be myElement(3).InnerText? And I tried all the myElement numbers and tried to see the output and with this code I have
Posted Image
I got msgboxes with blank results

Oh oops, I forgot to change the "http://" with my own one haha, one sec, sorry!

Dang, even after I replace it it still comes with blank results
Was This Post Helpful? 0
  • +
  • -

#8 Sheepings  Icon User is offline

  • D.I.C Addict

Reputation: 72
  • View blog
  • Posts: 571
  • Joined: 05-December 13

Re: How do I get the second href link in the <a> tag using vb.net

Posted 11 July 2014 - 07:59 AM

That is because the enumeration collection does not have what you are looking for in the source code, so it has nothing to select. Common issues generally come down to checking the wrong tag names and attributes. What is the page you are looking at? I would need to see the html source for myself.

Also, do you have option strict and explicit on?
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3729
  • View blog
  • Posts: 13,021
  • Joined: 12-December 12

Re: How do I get the second href link in the <a> tag using vb.net

Posted 11 July 2014 - 08:40 AM

Quote

Currently the "/get?ab" link is the third one, so does that mean it would be myElement(3).InnerText?

From my previous code (1) references the second element.. so, based on this, what would reference the third element?
Was This Post Helpful? 0
  • +
  • -

#10 WombatCombat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-July 14

Re: How do I get the second href link in the <a> tag using vb.net

Posted 11 July 2014 - 09:46 AM

View PostSheepings, on 11 July 2014 - 07:59 AM, said:

That is because the enumeration collection does not have what you are looking for in the source code, so it has nothing to select. Common issues generally come down to checking the wrong tag names and attributes. What is the page you are looking at? I would need to see the html source for myself.

Also, do you have option strict and explicit on?


This is the website : http://www.youtube-mp3.org/
I basically want to enter a youtube link and press convert which I have already coded and the only problem I have is pressing the purple "Download" button

Posted Image

View Postandrewsw, on 11 July 2014 - 08:40 AM, said:

Quote

Currently the "/get?ab" link is the third one, so does that mean it would be myElement(3).InnerText?

From my previous code (1) references the second element.. so, based on this, what would reference the third element?

Yeah I understand it this method, but the thing is this is hard coding, each time I put in a new link the position changes from second line to third to first and so on, so I can't hard code the number in which is why I'm confused.
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9487
  • View blog
  • Posts: 35,774
  • Joined: 12-June 08

Re: How do I get the second href link in the <a> tag using vb.net

Posted 11 July 2014 - 09:49 AM

Okay - now I am going to draw a line. What you are asking to interact with is very much contrary to the terms and service of youtube. Being such we cannot help you further here, and I will ask you do not persist in asking questions to help facilitate the trampling of youtube's terms of service. Additionally I will close the topic.

As always, if you have follow up questions on the 'why' feel free to shoot me a PM.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1