PDA

View Full Version : Get javascripts from a URL with VBA



MarsDK
03-21-2011, 01:26 AM
I am trying to use VBA to scrape some websites for information automatically.
I use an internetExplorer object, and has until now been able to get what I need through the

document.body.innerHtml

method.

Now however, the things I need are contained in a script in the header part of the page, more precisely, the page is page: hapag-lloyd.com//en/products_and_services/services_between_africa_and_asia.html
And I need the arrays in the header with ports etc.

Does anyone know how to acces that part of the file easily?

Kenneth Hobs
03-21-2011, 06:27 AM
You can parse the source text I guess. Here is one method to get the source text.

Sub Test_SourceTextToFileLB()
SourceTextToFileLB "http://www.hapag-lloyd.com/en/products_and_services/services_between_africa_and_asia.html", _
"C:\temp\services_between_africa_and_asia.txt"
Shell "Notepad C:\temp\services_between_africa_and_asia.txt", vbNormalFocus
End Sub

Function SourceTextToFileLB(url As String, toFile As String)
Dim Request As Object
Dim ff As Integer
Set Request = CreateObject("WinHttp.WinHttpRequest.5.1")

Request.Open "GET", url, False
Request.Send

ff = FreeFile
Open toFile For Output As #ff
Print #ff, Request.ResponseText
Close #ff

SourceTextToFileLB = Request.StatusText
End Function

MarsDK
03-21-2011, 01:11 PM
it works like a charm
Nice with a quick and good response,

Thanks a lot Kenneth,