Solved

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

Posted on 2014-01-12
4
270 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 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now