|
-
Jan 15th, 2010, 03:43 PM
#1
Thread Starter
Lively Member
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
-
Jan 15th, 2010, 04:08 PM
#2
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?
-
Jan 15th, 2010, 04:10 PM
#3
Thread Starter
Lively Member
Re: Get String From Webpage
 Originally Posted by kleinma
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
-
Jan 15th, 2010, 04:10 PM
#4
Re: Get String From Webpage
you are using VS2010 but targetting .NET 2.0?
-
Jan 15th, 2010, 04:12 PM
#5
Thread Starter
Lively Member
Re: Get String From Webpage
 Originally Posted by kleinma
you are using VS2010 but targetting .NET 2.0?
yea im just using 2.0 since it has everything that i need for this
-
Jan 15th, 2010, 04:15 PM
#6
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.
-
Jan 15th, 2010, 05:21 PM
#7
Thread Starter
Lively Member
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
-
Jan 15th, 2010, 05:44 PM
#8
Thread Starter
Lively Member
Re: Get String From Webpage
ok here is my code
vb Code:
Dim objRegEx As System.Text.RegularExpressions.Regex Dim objMatch As System.Text.RegularExpressions.Match Dim arrLinks As New System.Collections.ArrayList() ' Create regular expression objRegEx = New System.Text.RegularExpressions.Regex( _ "(?<=<a rel='lightbox' href=).*(?=>Image Only</a></td>)", _ System.Text.RegularExpressions.RegexOptions.IgnoreCase Or _ System.Text.RegularExpressions.RegexOptions.Compiled) ' Match expression to HTML objMatch = objRegEx.Match(HTML) ' Loop through matches and add <1> to ArrayList While objMatch.Success Dim strMatch As String strMatch = objMatch.Groups(1).ToString ListBox1.Items.Add(strMatch) objMatch = objMatch.NextMatch() 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|