+ Reply to Thread
Results 1 to 3 of 3

Pull Various Data From Web XML file -Copy Of XML Attached- :confused:

Hybrid View

  1. #1
    Registered User
    Join Date
    10-14-2011
    Location
    chesapeake, va
    MS-Off Ver
    Excel 2007
    Posts
    59

    Pull Various Data From Web XML file -Copy Of XML Attached- :confused:

    I'm trying to pull Data from XML files from the web, the info i'm trying to pull is Directors Name with link or as link, and producers Name, as link or with link.
    I have little experience with this, but have had a lot of help with code to the same idea, but this is above me completely. the code I have only pulls from the Movies Search string, and only pulls .ChildNodes(20).nodetypedvalue
    thanks for the time everyone


    HTML Code: 
    Xml
    550.zip
    Workbook
    MoviesV4.xlsm

    The Code I'm using now for extracting is in GetData_Click in the userform1

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Pull Various Data From Web XML file -Copy Of XML Attached- :confused:

    This will give you the attributes of each member of the cast.
        Set nodes = .getelementsbytagname("person")
        
        For Each nd In nodes
            For Each attr In nd.Attributes
               Debug.Print attr.Name & " - " & attr.Value
            Next attr
        Next nd

  3. #3
    Registered User
    Join Date
    10-14-2011
    Location
    chesapeake, va
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Pull Various Data From Web XML file -Copy Of XML Attached- :confused:

    So using the Code you Gave did in fact give me more a less the desired results, however right now I'm erroring out at this line at Sheets3 D58
    rng.Offset(0, 3).Value = nodes(nd + 1).Attributes(0).Value      'Lead Role
    Here's the code after i manipulated it to get what i could out of it. If i can't pull values from the line, I'd like to just leave the Cell value = ""

    Sub PersonsNode()
    Dim rngCode As Range
    Dim rng As Range
    Dim xml As Object
    Dim nodes As Object
    Dim Noded As Object
    Dim strURL As String
    Dim arrCat As Variant
    Dim PerNode As String
    Dim I As Long
    Dim j As Long
    Dim LastRow As Long
    
        LastRow = Worksheets("Data").Range("A" & Rows.Count).End(xlUp).Row
    
        Set rngCode = Sheets("Data").Range("D3")
        Set xml = CreateObject("MSXML2.DOMDocument")
    
        With xml
    
            Set rng = Sheets("sheet2").Range("A2")
            For j = 3 To LastRow
                Set rngCode = Sheets("Data").Range("D" & j)
    
                If Not rngCode <> "" Then
                GoTo 4
                Else
                    strURL = "http://api.themoviedb.org/2.1/Movie.getInfo/en/xml/644c8c7523000ff3de7cf4b0af9d4f8c/" & rngCode.Value
                    .Load strURL
    
                    Do: DoEvents: Loop Until .readyState = 4
                    
                    Set nodes = .getelementsbytagname("person")
                    
                        For Each nd In nodes
                    For Each attr In nd.Attributes
                        Debug.Print attr.Name & " - " & attr.Value
                        Next attr
                    Next nd
    On Error GoTo 4
                          If nodes.Length >= 0 Then
                          On Error GoTo 4
                            rng.Offset(0, 0).Value = nodes(nd).Attributes(0).Value      'Lead Role
                            rng.Offset(0, 1).Value = nodes(nd).Attributes(1).Value      'Starring Role
                            rng.Offset(0, 2).Value = nodes(nd).Attributes(2).Value      'Position
                            Else
                            End If
                            GoTo 1
    1
                            If nodes.Length >= 0 Then
                            On Error GoTo 4
                              rng.Offset(0, 3).Value = nodes(nd + 1).Attributes(0).Value      'Lead Role
                              rng.Offset(0, 4).Value = nodes(nd + 1).Attributes(1).Value      'Starring Role
                              rng.Offset(0, 5).Value = nodes(nd + 1).Attributes(2).Value      'Position
                              Else
                            End If
                            GoTo 2
                            
    2
                              If nodes.Length >= 0 Then
                              On Error GoTo 4
                                rng.Offset(0, 6).Value = nodes(nd + 2).Attributes(0).Value      'Lead Role
                                rng.Offset(0, 7).Value = nodes(nd + 2).Attributes(1).Value      'Starring Role
                                rng.Offset(0, 8).Value = nodes(nd + 2).Attributes(2).Value      'Position
                                Else
                            End If
                            GoTo 3
    3
                                If nodes.Length >= 0 Then
                                On Error GoTo 4
                                  rng.Offset(0, 9).Value = nodes(nd + 3).Attributes(0).Value      'Lead Role
                                  rng.Offset(0, 10).Value = nodes(nd + 3).Attributes(1).Value      'Starring Role
                                  rng.Offset(0, 11).Value = nodes(nd + 3).Attributes(2).Value      'Position
                                  Else
                            End If
                            GoTo 4
    4
    
                    Set rng = rng.Offset(1)
                End If
            Next j
        End With
        
        Worksheets("Sheet1").Range("A3:D3").EntireColumn.AutoFit
    End Sub
    Newest WorkBook vs:
    MoviesV5.xlsm
    Last edited by Spyderz; 10-27-2012 at 04:29 PM. Reason: Attached WorkBook

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1