Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A VBA web scraper to bulk copy the HTML from http://www.imsdb.com/scripts/.
Sub Scrape()
'Create an array of movie names
Dim Movies()
Movies = Array("Alien", "Avatar", "Blade-Runner", "Gattaca", "Ghostbusters", "Jurassic-Park", "Looper", "Lost-in-Space", "Sphere", "Signs", "Spider-Man", "Terminator", "V-for-Vendetta")
'Loop through each item in the movie array
For x = LBound(Movies) To UBound(Movies)
ActiveDocument.StoryRanges(wdMainTextStory).Delete
Script = "http://www.imsdb.com/scripts/" & Movies(x) & ".html"
Dim appIE As Object
Set appIE = CreateObject("InternetExplorer.Application")
With appIE
.Navigate Script
.Visible = True
End With
Do While appIE.Busy
DoEvents
Loop
ActiveDocument.Content.InsertAfter Text:=appIE.Document.body.innerHTML
On Error GoTo ErrorHandler
FilePath = "C:\Users\Desktop\Scripts\" & Movies(x) & ".doc"
ActiveDocument.SaveAs2 FilePath
appIE.Quit
'End Loop
Next x
ActiveDocument.Close
Application.Quit
ErrorHandler:
MsgBox Movies(x) & " could not be loaded."
Resume
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.