Javascript 使用VBScript从html中的特定节点提取值

Javascript 使用VBScript从html中的特定节点提取值,javascript,internet-explorer,vbscript,domxpath,Javascript,Internet Explorer,Vbscript,Domxpath,是否有任何方法可以使用Internet Explorer中的Vbscript提取特定html元素的DomXPath Sub WaitForLoad 'Sub to wait for browser to load Do While IE.Busy WScript.Sleep 10 Loop End Sub Dim IE Dim example1 Dim example2 Set IE = CreateObject("InternetExplorer.Applicat

是否有任何方法可以使用Internet Explorer中的Vbscript提取特定html元素的DomXPath

 Sub WaitForLoad 'Sub to wait for browser to load
 Do While IE.Busy
   WScript.Sleep 10
 Loop   
End Sub

Dim IE
Dim example1
Dim example2

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True 
    IE.navigate "http://www.lotteimall.com/goods/viewGoodsDetail.lotte?goods_no=12570568"
    WaitForLoad 

Set objRoot = ie.document

MsgBox objRoot.getElementById("win10").name


Dim vXPath : vXPath = "//*[@id='win10']"

Set example1 = objRoot.selectSingleNode(vXPath) 'this works for xml
Set example2 = objRoot.getElemetByXPath(vXPath) 'this works in javascript

'none of these works in IE html
IE文档对象中没有像“getElemetByXPath”这样的DomXPath函数,我仍然无法找到返回DomXPath的正确方法

至于javascript

    function XPath(elm) {
           for (segs = []; elm && elm.nodeType == 1; elm = elm.parentNode) {
             if (elm.hasAttribute('id')) {
               segs.unshift('id("' + elm.getAttribute('id') + '")')
               return segs.join('/')
             }
             else if (elm.hasAttribute('class'))
               segs.unshift(elm.localName.toLowerCase() + '[@class="' + elm.getAttribute('class') + '"]')
             else {
               for (i = 1, sib = elm.previousSibling; sib; sib = sib.previousSibling)
                 if (sib.localName == elm.localName) i++
               segs.unshift(elm.localName.toLowerCase() + '[' + i + ']')
             }
           }
           return segs.length ? '/' + segs.join('/') : null
    }
    var result = windows.document.evaluate("//div[@class='division_product_tab']//img", document, null, XPathResult.ANY_TYPE, null);

    var node, nodes = []
    while (node = result.iterateNext())
      nodes.push(XPath(node));

    console.log(nodes);
这将返回特定于对象的DomXpath。在本例中,“//div[@class='division\u product\u tab']//img”,它是img对象。但这只适用于开发工具

我希望可能有解决方案

您可以尝试:

Set oIE=CreateObject(“InternetExplorer.Application”)
与爱
.Visible=True
.导航“http://www.lotteimall.com/goods/viewGoodsDetail.lotte?goods_no=12570568"
请稍等片刻。忙碌或。准备就绪状态4
WScript.Sleep 10
环
执行While.Document.readyState“完成”
WScript.Sleep 10
环
Set oNode=.Document.querySelector(“div.division\u product\u tab img”)
MsgBox oNode.src
以

.querySelector()
返回第一个节点,而
.querySelector()
返回一组节点。

是否尝试了此代码
objRoot.getElementByXPath(vXPath)
在任何情况下都不起作用,你的意思是
getElementByXPath()
。另外,它是一个帮助函数,可以利用它不是vanilla JavaScript的一部分。yeap,它不是,我一直在寻找类似的方法,这些方法在VBScript中可用,可能是Tnx的副本,它似乎是目前唯一的解决方案:)