Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

15 Experts available now in Live!

Get 1:1 Help Now