`
benni82
  • 浏览: 122398 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

当当页面数据抓取备案

阅读更多

1.使用MetaStudio和DataScraper工具抓取当当图书畅销版内数据(书名,作者,出版社等)

 

工具下载地址  http://www.gooseeker.com/cn/node/download/front  按说明文档定制脚本

 

2. 抓取的数据为xml文件格式,每个xml文件对应一张页面的数据

 

3. 需要将所有xml文件合并成一个excel文件

使用宏

 

Sub xml2excel()
    Dim oxmlDoc As DOMDocument
    Dim Node As IXMLDOMNode
    Dim oXmlNodes As IXMLDOMNodeList
    Set oxmlDoc = New DOMDocument
    oxmlDoc.async = False
    'Rows("1:1").Select
    m = Dir(ThisWorkbook.Path & "\*.xml")
    Do While m <> ""
        oxmlDoc.Load ThisWorkbook.Path & "\" & m
        Set oXmlNodes = oxmlDoc.SelectNodes("/extraction/新书热卖榜/item")
        For j = 0 To oXmlNodes.Length - 1
           j2 = Range("a65536").End(xlUp).Row + 1
           For i = 0 To oXmlNodes(j).ChildNodes.Length - 1
              Cells(j2, i + 1) = oXmlNodes(j).ChildNodes(i).Text
           Next
        Next
        m = Dir
    Loop
            For i = 0 To oXmlNodes(0).ChildNodes.Length - 1
            Cells(1, i + 1) = oXmlNodes(0).ChildNodes(i).nodeName
            Next
End Sub

 

需要依赖Microsoft XML, 否则回报“用户自定义未找到”错误。

通过vba  工具--引入 选项完成依赖。

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics