Question Reading from a website to grab links

Superfurry

Member
Joined
Feb 8, 2011
Messages
19
Programming Experience
1-3
Hello I was wandering anyone could help I was wandering if I can push a button to read contents of a webpage and then print links into a textbox or something along those lines. Maybe search from a textbox to find keyword on webpage. Thankyou?
 
Use the HttpWebRequest class to read the contents of the webpage. You would likely have to search for the "<a href=" html tag in the returned html source.

VB.NET:
Dim request as HttpWebRequest = Ctype(WebRequest.Create(url), HttpWebRequest) 
Dim response as HttpWebResponse = Ctype(request.GetResponse(), HttpWebResponse)

Dim stream as Stream  = new Stream(response.GetResponseStream())
This will get you the webpage source html code. From there you can search the string to find anything you want.
 
It's a couple step search. Try looking up Regular expressions, or

search for the beginning of the address (identified by String.IndexOf("<a href=")+1)
search for the end of the address (identified by String.IndexOf(startIndex:= beginning of address, ">")
subtract the two numbers to get the length of the string

call String.Substring(beginning of address, length)

My numbers might be off a little, but you should be able to translate this to VB code and adjust the indexes to find the entire address. The example I've provided will get only the first link. To find other links, just start at the end of the last address (set startIndex:= end of last address).

It also assumes that there are no ">"s in your web address....not sure if it is a legal character or not for a web address.
 
I'm sorry I'm not that advanced how would I put that in my code I want to basicly type something in textbox and then it will find it on webpage that it's currently on, and maybe display results in another textbox? Sorry to be a pain


Thanks, superfurry :)
 
Back
Top