Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VBScript中使用Microsoft.XMLHTTP使用XPATH解析XHTML_Xpath_Vbscript_Html Parsing_Xmlhttprequest_Selectnodes - Fatal编程技术网

在VBScript中使用Microsoft.XMLHTTP使用XPATH解析XHTML

在VBScript中使用Microsoft.XMLHTTP使用XPATH解析XHTML,xpath,vbscript,html-parsing,xmlhttprequest,selectnodes,Xpath,Vbscript,Html Parsing,Xmlhttprequest,Selectnodes,我想用VBScript中的XPATH和Microsoft.XMLHTTP解析一个xhtml文档。我有以下xhtml文档结构。如何获取URL数组 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

我想用VBScript中的XPATH和Microsoft.XMLHTTP解析一个xhtml文档。我有以下xhtml文档结构。如何获取URL数组

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Local index</title>
    </head>
    <body>
        <table>
            <tr>
                <td>
                    <a href="url1.html">url1</a><br/>
                    <a href="url2.html">url2</a><br/>
                    <a href="url3.html">url3</a>
                </td><td>
                    <a href="url1-1.html">url1-1</a><br/>
                    <a href="url2-1.html">url2-1</a><br/>
                    <a href="url3-1.html">url3-1</a>
                </td>
            </tr>
        </table>
    </body>
</html>

局部索引





您确定需要使用过时的程序id
Microsoft.XMLHTTP
?如今,MSXML 3和MSXML 6都是操作系统支持的服务包的一部分,自Windows XP以来,它们都支持任何服务包。 关于使用XPath和MSXML 3,下面是一个示例:

Dim doc
Set doc = CreateObject("Msxml2.DOMDocument.3.0")
doc.validateOnParse = False
doc.resolveExternals = False
If doc.load("file.xml") Then
  doc.setProperty "SelectionLanguage", "XPath"
  doc.setProperty "SelectionNamespaces", "xmlns:xhtml='http://www.w3.org/1999/xhtml'"
  For Each link In doc.selectNodes("//xhtml:a")
    WScript.Echo(link.getAttribute("href") & ": " & link.text)
  Next
Else
  WScript.Echo(doc.parseError.reason)
End If

谢谢没有意识到我必须设置选择名称空间。我在C#上找到了一个类似的例子。