ASP 如何读取其它网站的网页内容?

抓取网页内容的方法有好多种,从最基本的基于Socket和Http协议的网络接口到利用一些现成的组件,比如windows internet transfer control控件。

这里,我想说一下MSXML对象库。

Msxml对象默认应该是安装在win2000系统上的吧,其基本的使用方式如下:
<%
    url = "http://blog.imwebs.com/tag.asp"
    set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    xmlhttp.open "GET", url, false
    xmlhttp.send ""
    Response.write xmlhttp.responseText
    set xmlhttp = nothing
%>


如果url地址不正确的话,就回返回这样的错误信息:
引用内容 引用内容
msxml4.dll (0x80072EE7)
Server name or address could not be resolved


当然也可以通过xmlhttp对象post数据:
<%
    url = "http://blog.imwebs.com/tag.asp"
    set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    xmlhttp.open "POST", url, false
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xmlhttp.send "x=1&y=2"
    Response.write xmlhttp.responseText
    set xmlhttp = nothing
%>

[本日志由 parno 于 2007-05-09 12:35 AM 编辑]
上一篇: iframe 大小自动适应内容的脚本
下一篇: 在 Web 网页上使用VBscript 和 Jscript
文章来自: 网络
引用通告: 查看所有引用 | 我要引用此文章
Tags: ASP 网络
相关日志:
评论: 0 | 引用: 0 | 查看次数: 8442