Grabbing xml data from site for each movie title

JoeSalmi

Board Regular
Joined
Jan 31, 2011
Messages
128
:confused: I have a list of movie names in B1:B1000 and I would like help grabing the following data from "http://www.omdbapi.com/?t=".

The data I need to grab goes into these fields,
D:D - Year
E:E - Rated
F:F - Run Time
G:G - Genre
H:H - Plot
I:I - Poster
J:J - Imdb Rating
K:K - ImdbID


and so on.

Example: in B1 I have:

Data extracted from: http://www.omdbapi.com/?t=After Earth&r=XML

ru7ghs.jpg



Thank you in advance to who ever can solve this riddle.

Joe

If omdbapi doesn't have a result in a section like there is no "run time" or something that field can be left blank, Also if there is more than one movie I would like it to grab the most recent version. A good example of this would be "The Karate Kid". Everyone knows the original was much better but I do own both productions however I can catch those manually UNLESS it's not too much trouble to have it ask me or have me verify it... Either way is okay with me.

Thanks again
 
Last edited:
Code:
Sub getmovies()
Dim mXml As Object: Set mXml = CreateObject("MSXML2.XMLHTTP")
Dim dom As Object: Set dom = CreateObject("MSXML2.DOMDocument")
Dim j As Integer: j = 2
    While Not Range("B" & j).Value = vbNullString
        With mXml
            .Open "GET", "http://www.omdbapi.com/?t=" & Range("B" & j).Value & "&r=XML", False
            .send
            dom.LoadXML .responseText
        End With
        If dom.SelectNodes("//root").Item(0).Attributes(0).Text Then
            With Range("B" & j)
                .Offset(0, 2) = dom.SelectNodes("//movie").Item(0).Attributes(1).Text
                .Offset(0, 3) = dom.SelectNodes("//movie").Item(0).Attributes(2).Text
                .Offset(0, 4) = dom.SelectNodes("//movie").Item(0).Attributes(4).Text
                .Offset(0, 5) = dom.SelectNodes("//movie").Item(0).Attributes(5).Text
                .Offset(0, 6) = dom.SelectNodes("//movie").Item(0).Attributes(9).Text
                .Offset(0, 7) = dom.SelectNodes("//movie").Item(0).Attributes(13).Text
                .Offset(0, 8) = dom.SelectNodes("//movie").Item(0).Attributes(15).Text
                .Offset(0, 9) = dom.SelectNodes("//movie").Item(0).Attributes(17).Text
             End With
        Else
            Range("B" & j).Offset(0, 2).Resize(1, 8) = "Movie not found."
        End If
        j = j + 1
    Wend
Set mXml = Nothing
Set dom = Nothing
End Sub
 
Upvote 0
HOLY CRAP I thought for sure no one would get this one.... AWESOME JOB bro it works PERFECTLY.... You rock my man...
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top