vbscript manipulation help -

Discussion in 'C#' started by grobar, Aug 13, 2006.

  1. #1
    I have a small snippet that captures the html of an external url, and stores it in "xmlhttp.responseText"

    I want to be able to pick out a section based on one other variable, "isknown", which is a url that would be in an href="" attribute of the <A> tag.

    Basically, I want to say:

    if the url "known" exists in the html anywhere then

    move forward in the code until the unknown anchor text is found, and capture that, and store as a variable.

    else

    send error

    end if

    I think I can use inStr() to find if the url exists,but not sure wehre i can go from there.
     
    grobar, Aug 13, 2006 IP
  2. fluid

    fluid Active Member

    Messages:
    679
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    70
    #2
    I suppose you are writing a crawler sort of thing. Your best bet is to use regular expressions and iterate until you have no more matches.

    dim HtmlLinks as String = @"<a[^>]*?href\s*=\s*[""']?"; ' modify this regular expression to suit your needs

    C#
    MatchCollection mc = Regex.Matches(xmlhttp.responseText.ToString(), HtmlLinks);
    foreach (Match mm in mc)
    {
    // what you want to do here
    }

    Although i've written it in C#, you should be able to easily convert in to VBScript after you've read about Regular Expressions.
     
    fluid, Aug 13, 2006 IP
  3. grobar

    grobar Well-Known Member

    Messages:
    642
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    140
    #3
    grobar, Aug 13, 2006 IP