VB.ne t Excel Add-in autmatically download data from a web page

Hi

What VB.net code would I use to automatically download data from a web page into Excel?

Is this even possible?
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Jacques Bourgeois (James Burger)Connect With a Mentor PresidentCommented:
After referencing System.Net in your project, you can download the pages with code like the following:

     Dim client As New System.Net.WebClient
     Dim page As String = client.DownloadString("http://www.<YourSite>/<YourPage>.html)

You will need to analyze the page html to find ways to identify the location of the data you are looking for. You can then use string methods on variable page to isolate portions of the page that contains what you need.

As an example, the following first looks in the page for the position of the text "Yearly sales " followed by a bold tag, and then retrieves the 6 characters following the tag to get the data. The 16 is the length of the text you were looking for.

     Dim position As Integer
     Dim data As String

     position = page.IndexOf("Yearly sales <b>") + 16
     data = page.Substring(position, 6)

Note that it won't work with all pages. In order to prevent the possibility of somebody downloading a page, changing the data and reposting it somewhere else with erroneous data, some pages contains an image instead of html text. In such a case, the only possible way to retrieve the data would be to send the image through OCR software to transform the page into text before doing the analysis.
0
 
Éric MoreauSenior .Net ConsultantCommented:
it greatly depends on which Web site it is.
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
I want to download tourist information from a range of websites in South Africa. Is there a way to grab information from website pages?
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much. Appreciate the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.