Skip to content

Instantly share code, notes, and snippets.

@gifguide2code
Created April 15, 2018 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gifguide2code/08b962dab584263214648875d5f9ca91 to your computer and use it in GitHub Desktop.
Save gifguide2code/08b962dab584263214648875d5f9ca91 to your computer and use it in GitHub Desktop.
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