求教高手,如何把一个url对应的html文件保存到一个字符串中,高分

handwolf 2005-04-23 12:13:43
如何把一个url对应的html文件保存到一个字符串中

我想把url对应的html文件保存到一个字符串中,然后进行搜索,如何实现!

谢谢了!
...全文
141 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dyb628 2005-04-25
  • 打赏
  • 举报
回复
Set xmlHttp = CreateObject("Msxml2.XMLHTTP") '创建对象
On Error Resume Next '出错处理
xmlHttp.Open "POST", "http://weather.china.com.cn/weather_travel24.php", False '用POST方式打开连接,异步执行。
xmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" '上传表单
xmlHttp.Send
If Err.Number = 0 Then '如果连接正确
retStr = xmlHttp.responseTEXT '等待并获得服务端返回的结果字符串
Else
retStr = "Url not found" '否则返回出错信息
End If

' 如果调用的是动态也面!使用下面函数可显示出中文!否者:)全是“??????”哈哈!
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function

最后用
response.write xmlHttp.responseTEXT 或 response.write xmlHttp.responseBODY
可以看到内容!内容怎么处理!就看自己的想法了!:)
其他的事自己做了!把URL换成你想要的就是了!
jFresH_MaN 2005-04-25
  • 打赏
  • 举报
回复
有的网页需要在url最后传参数的,有的是直接get方式,有的是post方式
前者直接在url后面加就可以了
后者需要再自己写入xxx=yyy这样形式的请求。。
handwolf 2005-04-25
  • 打赏
  • 举报
回复
up
  • 打赏
  • 举报
回复
<html>
<head>
<%
Dim objXMLHTTP, xml
Set xml = CreateObject("Microsoft.XMLHTTP")
xml.Open "GET","http://localhost/website/manageindex.htm", False
xml.Send

Function bin2str(binstr)
Dim varlen,clow,ccc,skipflag
'中文字符Skip标志
skipflag=0
ccc = ""
If Not IsNull(binstr) Then
varlen=LenB(binstr)
For i=1 To varlen
If skipflag=0 Then
clow = MidB(binstr,i,1)
'判断是否中文的字符
If AscB(clow) > 127 Then
'AscW会把二进制的中文双字节字符高位和低位反转,所以要先把中文的高低位反转
ccc =ccc & Chr(AscW(MidB(binstr,i+1,1) & clow))
skipflag=1
Else
ccc = ccc & Chr(AscB(clow))
End If
Else
skipflag=0
End If
Next
End If
bin2str = ccc
End Function
function utf2str(binstr)

end function

%>

</head>

<body>
<%
response.Write bin2str(xml.responseText)
%>
</body>

</html>
handwolf 2005-04-23
  • 打赏
  • 举报
回复
up一下:
顺便问一下,为什么下面的代码有些网页打不开呢?直接用ie是可以打开的
<%
'常用函数

'1、输入url目标网页地址,返回值getHTTPPage是目标网页的html代码
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
end function

'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
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




'下面试着调用http://www.3doing.com/earticle/的html内容
Dim Url,Html
Url="http://jjdhgi03.21trader.com/model1/indexc.jsp"
Html = getHTTPPage(Url)
Response.write Html
%>
fantiny 2005-04-23
  • 打赏
  • 举报
回复
xmlHttp读取后,保存为变量,然后搜索。搜索可以用substring,indexof等。
xmlHttp你可以搜索一下web版,很多人都问过了。详细的代码很多。

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧