0

多年来我没有使用过 MSXML2.ServerXMLHTTP,现在我需要使用。当我使用 MSXML2.ServerXMLHTTP 抓取页面时,该页面返回带有损坏的图像。我记得过去这样做过,我会使用一行代码,图像会完美解析。这有点像设置基本网址。有谁知道代码是什么?这是我正在使用的代码:

url = "notimportant.com"

Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
    objXML.Open "GET", URL, False
    objXML.Send()
    xmlResponse = objXML.responseText
Set objXML = Nothing
4

1 回答 1

1

您可能希望在其中放置一个<base>标签,<head>以便一行代码必须如下:

xmlResponse = Replace(objXML.responseText, "<head>", "<head><base href=""http://notimportant.com/"" />", 1, 1, vbTextCompare)

或者作为一种更可靠的方式,在 head 标签比较复杂和不可预测的情况下<head class="head etc">,您可以使用正则表达式来替换:

Dim Re
Set Re = New RegExp
    Re.IgnoreCase = True
    Re.Pattern = "<head[^>]*>"

xmlResponse = Re.Replace(objXML.responseText, "$&<base href=""http://notimportant.com/"" />")
于 2016-06-09T07:05:03.500 回答