xml - Excel VBA - 如何从 XML URL 获取数据?
问题描述
我需要从 FIELD NAME="sitr2" & FIELD NAME="sitr4" 获取数据。下面是 XML 代码:
<SEGMENTS>
<SEGMENT NAME="webcluster">
<RESULTPAGE>
<QUERYTRANSFORMS>...</QUERYTRANSFORMS>
<NAVIGATION ENTRIES="0"> </NAVIGATION>
<CLUSTERS/>
<RESULTSET FIRSTHIT="1" LASTHIT="1" HITS="1" TOTALHITS="1" MAXRANK="10000" TIME="0.5673">
<HIT NO="1" RANK="10000" SITEID="0" MOREHITS="0" FCOCOUNT="0">
<FIELD NAME="rank">10000</FIELD>
<FIELD NAME="personnames"/>
<FIELD NAME="concepts">environment;flexible;storage;virtual;growing</FIELD>
<FIELD NAME="companyteaser"/>
<FIELD NAME="locationteaser"/>
<FIELD NAME="personnameteaser"/>
<FIELD NAME="nav">...</FIELD>
<FIELD NAME="taxonomy">t/na</FIELD>
<FIELD NAME="documentid"/>
<FIELD NAME="uniqueid"/>
<FIELD NAME="sitr1">4038b5c5-c90b-4ae3-a165-a5e0db9c10d4</FIELD>
<FIELD NAME="sitr2">097cf4a8-2755-4c62-939c-9402e0a4e3e2</FIELD>
<FIELD NAME="sitr3">Unknown</FIELD>
<FIELD NAME="sitr4">0.3</FIELD>
<FIELD NAME="sitr5"/>
<FIELD NAME="sitr8"><matches> </matches></FIELD>
<FIELD NAME="int1">21854</FIELD>
我不知道从哪里开始。我需要提取并插入到excel中。希望有人可以帮助我。
解决方案
您可以使用 Internet Explorer。如何在 VBA 中使用 IE 的起始页在这里:wiseowl
在您的情况下,代码将是:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub main()
Dim ie As Object
Application.ScreenUpdating = True
Set ie = CreateObject("internetexplorer.application")
With ie
.Visible = True
.navigate "C:\Temp\some.xml"
Do While ie.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
End With
Sleep 300
With ie.document.all.tags("FIELD")
For i = 0 To .Length - 1
Cells(i + 1, 1) = .Item(i).getAttribute("NAME")
Next i
End With
ie.Quit
Set ie = Nothing
End Sub
推荐阅读
- python - Scrapy AttributeError:'Selector'对象没有属性'extract_first'
- java - 使用Arraylist进行排序时如何在ArrayList中的特定位置添加元素?
- angular - Angular mat-icon 正在“翻译”?
- api - 成员和管理员用户的 API 端点
- docker - 如何将 NGINX 正确配置为 tine20 docker 容器(与 Apache2 一起运行)的反向代理?
- vue.js - 类之间的区别(vuejs)
- r - 如果具有名称的列包含部分值,则保留行
- android - 真彩色图标显示黑色背景
- python-3.x - 如何将整个 tkinter 画布截图为 png 或 pdf
- cassandra - 当 cassandra 似乎正在运行和收听但 cqlsh 无法连接时,我应该尝试什么?