9core.com - 九核技术交流网

九百链
为了更好的解决实际工作中遇到的问题,本站开设了QQ群 ASP+PHP+JSP+.NET①:9793624
ASP+PHP+JSP+.NET②:17775294
网站通告: 新开设QQ群,群号:17775294 九核WEB技术专业论坛 官方QQ群 9793624
搜索: 您的位置主页> 程序开发 > Asp技术 >阅读资讯: ASP采集中获取网页内所需的html代码

ASP采集中获取网页内所需的html代码

文章来源:互联网 发表时间:2008-09-12 点击次数

有时候,需要获取网页的html代码,如新闻采集。采集之前,首页要得到被采集的页面的html代码,然后根据代码,分析出你想要得到的内容,最后将得到的内容保存到自己的数据库中

RWT4UqzpY5dZEWSqMZ60BVS4uigV5jXqlwCo47os

function.asp


<%
Function getHTTPPage(url)
On Error Resume Next
dim http
set http=Server.createobject("Microsoft.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
Response.Write "<p align='center'><font color='red'>
<b>服务器获取文件内容出错</b></font></p>"
Err.Clear
End If 
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
%>

index.asp

<!--#include file="function.asp"-->
<%
url="http://www.google.cn"
response.write getHTTPPage(url)
%>

RWT4UqzpY5dZEWSqMZ60BVS4uigV5jXqlwCo47os
Asp
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助