MSXML2.ServerXMLHTTP使用经典的ASP返回破碎的图像
问题描述:
我有多年没有使用MSXML2.ServerXMLHTTP,现在我需要。当我使用MSXML2.ServerXMLHTTP来抓取页面时,页面将返回具有损坏的图像。我记得过去做过这样的事情,我使用了一行代码,图像可以完美解决。这有点像设置基本网址。有谁知道代码会是什么?下面是我使用的代码:MSXML2.ServerXMLHTTP使用经典的ASP返回破碎的图像
url = "notimportant.com"
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", URL, False
objXML.Send()
xmlResponse = objXML.responseText
Set objXML = Nothing
答
你可能要放置<head>
内<base>
标签,这样的一行代码必须是以下几点:
xmlResponse = Replace(objXML.responseText, "<head>", "<head><base href=""http://notimportant.com/"" />", 1, 1, vbTextCompare)
但作为更可靠在头部标签比较复杂且不可预知的情况下,您可以使用正则表达式来替换:
Dim Re
Set Re = New RegExp
Re.IgnoreCase = True
Re.Pattern = "<head[^>]*>"
xmlResponse = Re.Replace(objXML.responseText, "$&<base href=""http://notimportant.com/"" />")
您如何获得图像。如果'xmlResponse'包含'img'标签,那么您需要查看源代码并找出它们可能存在的问题。 NB我推荐使用'Server.CreateObject(“MSXML2.ServerXMLHTTP.6.0”)' - 它调用最新版本的MSXML – John