dim wstr,str,url,start,over,dtime
url="http://mb.111cn.net/"
wstr=gethttppage(url)
body=wstr<%
'用asp获取远程目标网页指定内容
on error resume next
server.scripttimeout=9999999
function gethttppage(path)
t = getbody(path)
gethttppage=bytestobstr(t,"gb2312")
end function
function newstring(wstr,strng)
newstring=instr(lcase(wstr),lcase(strng))
if newstring<=0 then newstring=len(wstr)
end function
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 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'asp获取远程网页指定内容开始
dim wstr,str,url,start,over,dtime
a="开始内容" 'asp获取目标网页内容开始标记
b="结束内容" 'asp获取网页内容结束标记
url="http://mb.111cn.net/"
wstr=gethttppage(url)
start=newstring(wstr,a)
over=newstring(wstr,b)
body=mid(wstr,start,over-start)
response.write ""&body&"" '输出获取到的网页内容
'asp获取远程网页指定内容结束
%>
一款asp.net教程 采集远程服务器数据
'using system;
using system.collections.generic;
using system.text;
using system.net;
using system.io;namespace thief
{
class program
{
static void main(string[] args)
{
try {
webclient mywebclient = new webclient();mywebclient.credentials = credentialcache.defaultcredentials;//获取或设置用于对向internet资源的请求进行身份验证的网络凭据。
byte[] pagedata = mywebclient.downloaddata("http://www.111cn.net");//从指定网站下载数据
string pagehtml = encoding.default.getstring(pagedata); //如果获取网站页面采用的是gb2312,则使用这句
//string pagehtml = encoding.utf8.getstring(pagedata); //如果获取网站页面采用的是utf-8,则使用这句
console.writeline(pagehtml);//在控制台输入获取的内容
using (streamwriter sw = new streamwriter("c: estouput.html"))//将获取的内容写入文本
{
sw.write(pagehtml);
}console.readline(); //让控制台暂停,否则一闪而过了
}catch(webexception webex) {
console.writeline(webex.message.tostring());
}
}
}
}