Get URL Anchor Text Using WebRequest

Discussion in 'Visual Basic .NET' started by mixing, Jan 15, 2015.

  1. mixing

    mixing Regular Member

    Joined:
    Jan 18, 2014
    Messages:
    297
    Likes Received:
    35
    Gender:
    Male
    Location:
    USA
    I'm currently making a webrequest to a site, downloading the response, and putting it into a string. Now I want to search through that string and look for a particular domain (txtDomain.text)...When I find that domain, I want to extract the anchor text for it. It could be formatted a few different ways though:

    Code:
    <a href="http://www.domain.com">Anchor Text</a>
    
    Code:
    <a href="http://www.domain.com" target="_blank">Anchor Text</a>
    
    Code:
    <a href="http://www.domain.com" title="this title" target="_blank">Anchor Text</a>
    
    Does anyone know the best way to go through, find the domain, and pull just the Anchor Text as shown above?

    Thanks!
     
  2. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    975
    Likes Received:
    682
    Occupation:
    Web/Bot Developer
    Nevermind... I didn't realize this was VB/.NET section prior to posting. My bad.
     
    Last edited: Jan 15, 2015
  3. qrazy

    qrazy Senior Member

    Joined:
    Mar 19, 2012
    Messages:
    1,115
    Likes Received:
    1,726
    Location:
    Banana Republic
    Just use a library like HTMLAgilityPack which has many helper functions related to HTML/DOM parsing.