Results 1 to 8 of 8

Thread: Get String From Webpage

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Get String From Webpage

    I am trying to get several strings from a web page and add them to a listbox

    each string I need to grab falls in between these two strings

    Code:
    <a rel='lightbox' href='
    And
    Code:
    '>Image Only</a></td>
    there will be several of these strings on the same page

    I am pretty sure I can use string splits to do this but could use a little help to figure it out

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Get String From Webpage

    In a webbrowser control or you just want to download the string behind the scenes and get the data? What version of Visual Studio?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Re: Get String From Webpage

    Quote Originally Posted by kleinma View Post
    In a webbrowser control or you just want to download the string behind the scenes and get the data? What version of Visual Studio?
    just behind the scenes, 2010 .net framework 2

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Get String From Webpage

    you are using VS2010 but targetting .NET 2.0?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Re: Get String From Webpage

    Quote Originally Posted by kleinma View Post
    you are using VS2010 but targetting .NET 2.0?
    yea im just using 2.0 since it has everything that i need for this

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Get String From Webpage

    Your best bet then would be regular expressions. You could manually parse out the data however that would be a much more complex cumbersome approach.

    If you were using a newer version of the framework, then sometimes you can make use of things like XML literals where you can load a webpage into an XML document (if the webpage is infact well formed) and query data directly from that. Even if its not well formed (ie no root element) you can usually grab part of the text and load it as an XML fragment and still query/parse it easily.

    Or if you were using a browser control, you could make use of the DOM objects the .NET framework exposes to parse the data.

    Since you are just using .NET 2.0 and want to do it behind the scenes, try doing a search on here for regex and maybe a few other keywords like webpage, because there have been quite a few examples of this on here.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Re: Get String From Webpage

    what would be the regex expression be? I've been looking and can not figure out exactly what it would be

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Re: Get String From Webpage

    ok here is my code
    vb Code:
    1. Dim objRegEx As System.Text.RegularExpressions.Regex
    2.         Dim objMatch As System.Text.RegularExpressions.Match
    3.         Dim arrLinks As New System.Collections.ArrayList()
    4.         ' Create regular expression
    5.         objRegEx = New System.Text.RegularExpressions.Regex( _
    6.             "(?<=<a rel='lightbox' href=).*(?=>Image Only</a></td>)", _
    7.             System.Text.RegularExpressions.RegexOptions.IgnoreCase Or _
    8.             System.Text.RegularExpressions.RegexOptions.Compiled)
    9.         ' Match expression to HTML
    10.         objMatch = objRegEx.Match(HTML)
    11.         ' Loop through matches and add <1> to ArrayList
    12.         While objMatch.Success
    13.             Dim strMatch As String
    14.             strMatch = objMatch.Groups(1).ToString
    15.             ListBox1.Items.Add(strMatch)
    16.             objMatch = objMatch.NextMatch()
    17.         End While

    but it is just adding blank lines to the listbox and not the strings it found


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width