Solved

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

Posted on 2014-01-12
4
271 Views
Last Modified: 2014-01-12
Hi

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

Is this even possible?
0
Comment
Question by:murbro
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39774782
it greatly depends on which Web site it is.
0
 

Author Comment

by:murbro
ID: 39774816
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
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39775039
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
 

Author Closing Comment

by:murbro
ID: 39775140
Thanks very much. Appreciate the help
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question