XMLHTTP后如何更改目标网页路径
用XMLHTTP获取目标网页内容时一般是跨域或者在不同的目录,而源网页链接路径一般是“../images/logo.gif”,如何换成“http://源url/images/logo.gif”?
请在这个基础上修改
<%
Function getHTTPPage(Path)
t = GetBody(Path)
getHTTPPage=BytesToBstr(t,"GB2312")
End function
Function GetBody(url)
on error resume next
Set Retrieval = CreateObject
("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
GetBody = .ResponseBody
End With
Set Retrieval = Nothing
End Function
'调用XMLHTTP组件创建一个对象并进行初始化设置。
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject
("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
Function Newstring(wstr,strng)
Newstring=Instr(lcase(wstr),lcase(strng))
if Newstring<=0 then Newstring=Len(wstr)
End Function
%>
<% '处理抓取回来的数据调用adodb.stream组件并进行初始化设置。
url=""
'获取指定页面的全部数据
wstr=getHTTPPage(url)
wstr=GetAbsUrl(wstr)
response.write wstr
%>
参考答案:两种解决方法:
1、在网页里加入HTML“<base href=\"<%=URL%>\">”
1、可以用Replace,
Replace(wstr,\"src=\"\"../\",\"***.com/\")