4 Replies - 20047 Views - Last Post: 15 January 2010 - 08:14 PM Rate Topic: -----

#1 echoz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 08-November 09

How to get data from a website to my desktop application ?!

Posted 13 December 2009 - 01:38 PM

hi all,

this website " http://www.oanda.com...istorical-rates " contains currency exchange rate, and it's useful
to my desktop application " bill system " .

the question is: How to get data from this website to my desktop application textboxes ?!!

any help ?!

thanx ;)

Is This A Good Question/Topic? 0
  • +

Replies To: How to get data from a website to my desktop application ?!

#2 LeisureProgrammer  Icon User is offline

  • N00by VB.NET Developer
  • member icon

Reputation: 110
  • View blog
  • Posts: 588
  • Joined: 06-September 09

Re: How to get data from a website to my desktop application ?!

Posted 13 December 2009 - 03:12 PM

To get the data from their website, you would have to do some "minor hacking" operations... However, for some websites you won't...

Do you want current rates? If so, just use this website, or anyother which gives the current rates in *plain text* or html
http://api.finance.x.../api/latest.xml

Here's how to get the website's source code- import system.net first
 Dim blah As New System.Net.WebClient
		blah.DownloadString("http://api.finance.xaviermedia.com/api/latest.xml")
		'then do some string manipulation to get what you want, the base currency is EUR, so convert the rates to USD using the rates in here



Or to find historical dates, use a URL like this:
dim year as string
dim month as string
dim day as string

dim url as string = "http://api.finance.xaviermedia.com/api/" & year & "/" & month & "/" & day & ".xml"



If you're going to share this app with strangers and are going to use this site, I suggest you include a link to "http://finance.xaviermedia.com/ " to avoid any legal issues.

This post has been edited by LeisureProgrammer: 13 December 2009 - 03:19 PM

Was This Post Helpful? 1
  • +
  • -

#3 echoz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 08-November 09

Re: How to get data from a website to my desktop application ?!

Posted 14 December 2009 - 11:55 AM

Thanx ( LeisureProgrammer ) ... that's nice :D

But the based rate is the "EURO" only, and user can't change it in this website ( http://api.finance.x.../api/latest.xml ).

This one is better: " http://www.oanda.com...istorical-rates "
because it contains:
( 1 ) All currencies.
( 2 ) User can choose the base currency.

Can you (or any one else) help me getting data from it?!

Thanx ;)
Was This Post Helpful? 0
  • +
  • -

#4 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: How to get data from a website to my desktop application ?!

Posted 14 December 2009 - 01:53 PM

I guess if you are still struggling you could screen scrape. This is where you have a website and you rip content from a frame or box, or even a label. Basically you could do this two ways:
1. use the internet explorer Component and GetElementByID
2. Read it from the web page source (a bit harder)

Anyway here is an interesting read, search for "5.2.1 Frames" its a bit old but it carry's the same message.

Anyway enjoy,
Was This Post Helpful? 0
  • +
  • -

#5 DaveCS  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 08-January 10

Re: How to get data from a website to my desktop application ?!

Posted 15 January 2010 - 08:14 PM

Using the Webbrowser control I came up with a simple solution.
(Project attached)
First load navigate to the page.
Second automate clicking "Get Rates"
Third retrieve the results from the table and display in a textbox.
Project contains
A form
A Webbrowser control
A toolstrip with 3 buttons and one Toolstriptextbox
A textbox to show the results
Posted Image

Public Class Form1
	Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
		WebBrowser1.Navigate(ToolStripTextBox1.Text)
	End Sub
	Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
		'Find and Click The "Get Table" button
		Dim theWElementCollection As HtmlElementCollection = WebBrowser1.document.All
		For Each curElement As HtmlElement In theWElementCollection
			If curElement.GetAttribute("value").Equals("Get Table") Then
				curElement.InvokeMember("click")
			End If
		Next
		'Result page should load. Normally we use feeback from the Webbrowser1 control
		'to determine if the new page is loaded.
		'In this test case we will just sleep for 5 seconds then get the rates
		'by clicking the third button in the toolstrip
		System.Threading.Thread.Sleep(5000)	
	End Sub

	Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
		'Get our rates and display in the textbox
		Dim ourTable As HtmlElementCollection = WebBrowser1.document.GetElementsByTagName("FONT")
		For Each el As HtmlElement In ourTable
			If el.GetAttribute("size").Contains("2") Then
				'Output the contents fo Textbox1
				TextBox1.Text += el.InnerText.ToString + vbNewLine
			End If
		Next
	End Sub
 End Class


Attached File(s)


This post has been edited by DaveCS: 15 January 2010 - 08:16 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1