Thursday, October 28, 2010

I am a VB 2005 newbie and am looking to populate a database with information extracted from webpage? How?

How can I go about extracting data for a MySQL database from information found on webpages using VB 2005?I am a VB 2005 newbie and am looking to populate a database with information extracted from webpage? How?
You're going to want to do what is called ';Screen Scraping';. To do this, you'll make use of the WebRequest class in the System.Net namespace.



string PageHtml = ';';;

string PageURL = ';http://www.yahoo.com';;



WebRequest objRequest = null;

StreamReader objStream = null;



//Create a request

objRequest = WebRequest.Create(PageURL);



//Get a stream from that request

objStream = new StreamReader( objRequest.GetResponse(). GetResponseStream() );



//Get the HTML for the page into your string

PageHTML = objStream.ReadToEnd();



From there, just parse the PageHTML string and insert data into your database as needed. I know this is in C# and you requested VB, but it's pretty simple to convert.

No comments:

Post a Comment