Log in

View Full Version : Grab data from Websites



Jeevie
09-19-2012, 12:09 AM
Hi All

Is there a way to grab specific data from websites using VBA in MS Access. Will using SendKeys help?

gcomyn
09-27-2012, 09:14 AM
I found this code on the web somewhere a while ago, and use it on the few databases that I have that get webpages...


'***** Begin of Code *******
'***
'***
'*** Call: a = Fetch("http://www.google.com","c:\google.html (http://www.google.com)")
'***
'*** return TRUE on success
'*** DOES NOT WORK

Public Function Fetch(URL, dest)
'On Error Resume Next
Dim b
Err.Clear
With CreateObject("Microsoft.XMLHTTP")
.Open "GET", URL, False
.send
b = .responseBody
If Err.Number <> 0 Or .Status <> 200 Then
Fetch = False
Exit Function
End If
End With

With CreateObject("ADODB.Stream")
.Type = 1
.Open
.Write b
.SaveToFile dest, 2
End With

Fetch = Err.Number = 0
End Function
'****** end of code *****


That will fetch the entire webpage.. then you can parse it how you need to.

GComyn

stanl
10-04-2012, 07:09 AM
Hi All

Is there a way to grab specific data from websites using VBA in MS Access. Will using SendKeys help?

For 'specific' data, you probably have to be more specific. If it's table data Excel has built-in methods under the Data menu and you can transfer to Access.

Assuming you are using IE, either an HTTP request, or direct web scraping using IE functions will get what you want. If you are attempting to fill table rows, for example, stock prices - web scraping is probably preferable, unless data can be obtained as XML or JSON in which case there are other tools to process those.