Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.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
Parsing 用ASP-classic解析html节点_Parsing_Html_Asp Classic - Fatal编程技术网

Parsing 用ASP-classic解析html节点

Parsing 用ASP-classic解析html节点,parsing,html,asp-classic,Parsing,Html,Asp Classic,我花了一天的时间试图找到一个答案:使用MSXML2.ServerXMLHTTP.6.0的经典ASP是否有可能解析html代码并根据给定的ID提取html节点的内容?例如: 远程html文件: <html> ..... <div id="description"> some important notes here </div> ..... </html> ..... 这里有一些重要的提示 ..... asp代码 <% .

我花了一天的时间试图找到一个答案:使用MSXML2.ServerXMLHTTP.6.0的经典ASP是否有可能解析html代码并根据给定的ID提取html节点的内容?例如:

远程html文件:

<html>
.....
<div id="description">
some important notes here
</div>
.....
</html>

.....
这里有一些重要的提示
.....
asp代码

<%    
    ...
    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    objHTTP.Open "GET", url_of_remote_html, False
    objHTTP.Send
    ...
%>


现在-我读了很多文档,可以作为源代码(objHTTP.responseText)和结构(objHTTP.responseXML)访问HTML。但在这个世界上,我如何使用XML响应来访问该div的内容呢?我阅读并尝试了这么多示例,但找不到任何明确的解决方法。

首先,按照原始代码片段执行GET请求:

Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.Open "GET", url_of_remote_html, False
http.Send
接下来,创建一个正则表达式对象,并将模式设置为将元素的内部html与所需id相匹配:

Set regEx = New RegExp
regEx.Pattern = "<div id=""description"">(.*?)</div>"
regEx.Global = True

如果出现任何错误,例如在文档中找不到匹配元素,
内容
将为
Null
。如果所有内容都转到了计划
中,则内容
应该包含您要查找的数据。

好的,正则表达式-当然:)谢谢!这对于独特的标签(这是我的情况)很好。多项式-再次感谢您,无需担心。如果您想从一个不太特定的标记中获取数据,或者从文档中的多个标记中获取数据,那么您可以编写不同的模式,并循环执行
Execute()
返回的匹配项—范围很大。
On Error Resume Next
contents = regEx.Execute(http.responseText)(0).Submatches(0)
On Error Goto 0