自己做采集程序_小偷/采集

现在网上的采集程序很多,但是有时候你发现一个好的网站,想自己做个采集工具采集一些信息,就需要自己去写程序了,其实这样的采集程序并不难写,主要是去分析源网站的网页结构。
首先去下载个XMLHTTP的类文件:
<%
Class xhttp
private cset,sUrl,sError
Private Sub Class_Initialize()
'cset="UTF-8"
cset="GB2312"
sError=""
end sub

Private Sub Class_Terminate()
End Sub

Public Property LET URL(theurl)
sUrl=theurl
end property
public property GET BasePath()
BasePath=mid(sUrl,1,InStrRev(sUrl,"/")-1)
end property
public property GET FileName()
FileName=mid(sUrl,InStrRev(sUrl,"/")+1)
end property
public property GET Html()
Html=BytesToBstr(getBody(sUrl))
end property

public property GET xhttpError()
xhttpError=sError
end property

private Function BytesToBstr(body)
on error resume next
'Cset:GB2312 UTF-8
dim objstream
set objstream = Server.CreateObject("adodb.stream")
with objstream
.Type = 1 '
.Mode = 3 '
.Open    
.Write body  '
.Position = 0 '
.Type = 2  '
.Charset = Cset  '
BytesToBstr = .ReadText '
.Close
end with
set objstream = nothing
End Function

private function getBody(surl)
on error resume next
dim xmlHttp
'Set xmlHttp=server.createobject("Msxml2.XMLHTTP.4.0")
'set xmlHttp=server.createobject("Microsoft.XMLHTTP")
set xmlHttp=server.createobject("MSXML2.ServerXMLHTTP")
xmlHttp.setTimeouts 10000,10000,10000,30000
xmlHttp.open "GET",surl,false
xmlHttp.send
if xmlHttp.readystate=4 then
'if xmlHttp.status=200 then
 getBody=xmlhttp.responsebody
'end if
 else
 getBody=""
end if

if Err.Number<>0 then
sError=Err.Number
Err.clear
else
sError=""
end if
set xmlHttp=nothing
end function

Public function saveimage(tofile,isoverwrite)
on error resume next
dim objStream,objFSO,imgs

if Not isoverwrite Then
 Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
 If objFSO.FileExists(Server.MapPath(tofile)) Then
  Exit Function
 End If
 Set objFSO = Nothing
End IF

imgs=getBody(sUrl)
Set objStream = Server.CreateObject("ADODB.Stream")
with objStream
.Type =1
.Open
.write imgs
.SaveToFile server.mappath(tofile),2
.Close()
end with
set objstream=nothing
end function

end class

%>
用了这个类文件,做起事情来就方便多了。
然后就可以分析采集网站的网页结构,写采集程序了。
下面给个例子:
<!--#include file="conn.asp"-->
<!--#include file="inc/xhttp_class.asp"-->
<!--#include file="inc/function.asp"-->
<%
server.ScriptTimeout = 1000
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>BT采集器</title>
</head>
<body>
<form name="form1" method="post" action="get81bt.asp">
分类ID:
  <input type="text" name="cid" value="<%=request("cid")%>"><br>
开始ID:
  <input type="text" name="startid" value="<%=request("startid")%>">
  <br>
  结束ID:
  <input type="text" name="overid" value="<%=request("overid")%>">
  <br>
  分类名称:<input type="text" name="classname" value="<%=request("classname")%>">为空自动获取
  <br>
  <input name="action" type="hidden" id="action" value="getdata">
  <input type="submit" name="Submit" value="采集">
</form>
当前ID:<%=request("id")%> <br>
<%
dim action

action = Request("action")
if action = "getdata" then
        cid = Request("cid")
        startid = Request("startid")
        overid = Request("overid")
        id = Request("id")       
        if id = "" then id = startid

        set objxhttp = new xhttp

        objxhttp.URL = "http://www.81dd.com/Class/"&cid&"_"&id&".htm"
        content = objxhttp.Html

        if InStr(content,"网站维护中") then
                call NextID
                response.End()
        end if

        list = GetContent(content,"<!--内容开始-->","<!--内容结束-->",0)

        Dim regEx, Match, Matches,patrn
        Set regEx = New RegExp
        patrn = "<a href=""../BtHtml/(.+?)"">"
        regEx.Pattern = patrn
        regEx.IgnoreCase = True
        regEx.Global = True
        Set Matches = regEx.Execute(list)
        on error resume next
        For Each Match in Matches

                'response.write Match.Value & "<br>"
                weburl = "http://www.81dd.com/BtHtml/" & regEx.Replace(Match.Value,"$1")
                response.write weburl & "<br>"
                response.Flush()

                objxhttp.URL = weburl
                cpage = objxhttp.Html       
                cpage = GetContent(cpage,"<!--内容开始-->","<!--内容结束-->",0)

                title = GetContent(cpage,"BT资源名称:<strong>","</strong>",0)
                title = stripHTML(title)

                IF Request("classname") <> "" then
                        classname = Request("classname")
                Else               
                        if InStr(title,"喜剧") then
                                classname = "喜剧"
                        Elseif InStr(title,"动作") then
                                classname = "动作"
                        Elseif InStr(title,"惊悚") then
                                classname = "惊悚"
                        Elseif InStr(title,"犯罪") then
                                classname = "犯罪"
                        Elseif InStr(title,"恐怖") then
                                classname = "恐怖"
                        Elseif InStr(title,"爱情") then
                                classname = "爱情"
                        Elseif InStr(title,"冒险") then
                                classname = "冒险"
                        Elseif InStr(title,"科幻") then
                                classname = "科幻"
                        Elseif InStr(title,"悬念") then
                                classname = "悬念"
                        Elseif InStr(title,"奇幻") then
                                classname = "奇幻"
                        Elseif InStr(title,"战争") then
                                classname = "战争"
                        Elseif InStr(title,"连续剧") then
                                classname = "连续剧"
                        Elseif InStr(title,"综艺") then
                                classname = "综艺"
                        Elseif InStr(title,"灾难") then
                                classname = "灾难"
                        Elseif InStr(title,"伦理") then
                                classname = "伦理"
                        Elseif InStr(title,"动漫") or InStr(title,"动画") then
                                classname = "动漫"
                        Elseif InStr(title,"国语") or InStr(title,"集") then
                                classname = "其他影视"
                        Else
                                classname = "其他"
                        End if
                End IF

                intro = GetContent(cpage,"<tr><td width=770 bgcolor=#FFFFFF><div style=""margin:10px;line-height:150%"">","</div>",0)
                intro = Replace(intro,"<br />","[br]")
                intro = Replace(intro,"<BR />","[br]")
                intro = Replace(intro,"<BR>","[br]")
                intro = Replace(intro,"<br>","[br]")
                intro = Replace(intro,"<p>","[p]")
                intro = Replace(intro,"<P>","[p]")
                intro = Replace(intro,"</p>","[/p]")
                intro = Replace(intro,"</P>","[p]")
                intro = Replace(intro,"<img","[img")
                intro = Replace(intro,"<IMG","[img")       
                intro = stripHTML(intro)
                intro = Replace(intro,"[br]","<br>")
                intro = Replace(intro,"[p]","<p>")
                intro = Replace(intro,"[/p]","</p>")
                intro = Replace(intro,"[img","<img")
                intro = Replace(intro,"[img]","<img src=")
                intro = Replace(intro,"[/img]",">")
                intro = Replace(intro,"[IMG]","<img src=")
                intro = Replace(intro,"[/IMG]",">")
                'response.write t
                'response.End()

                addtime = Trim(GetContent(cpage,"发布时间:"," ",0))
                if Not IsDate(addtime) then addtime = now()

                username = "bt"

                filesize = GetContent(content,"BT文件大小:"," ",0)

                title2 = title

                downurl = GetContent(cpage,"<a style=""color:red"" href=""","""",0)

                p = CDate(addtime)
                Dim sRnd
                Randomize
                sRnd = Int(900 * Rnd) + 100
                sFileName = year(p) & month(p) & day(p) & hour(now) & minute(now) & second(now) & sRnd & ".torrent"

                url = "torrent/" & year(p) & "-" & month(p) & "-" & day(p) & "/" & sFileName
                Call CreateF(url)

                'Text
                Response.Write classname & "<br>"
                Response.write title & "<br>"
                'response.Write intro & "<br>"
                'response.Write addtime & "<br>"
                'response.Write username & "<br>"
                'response.Write filesize & "<br>"
                response.Write downurl & "<br>"
                response.Write url & "<br>"
                response.Flush()

                'response.End()
                'database

                if err.number = 0 then
                        if (Not IsNull(title)) and title <> "" and downurl <> "" then
                                set rs = server.CreateObject("adodb.recordset")
                                sql = "select * from bt_class where classname = '" & classname & "'"
                                rs.open sql,conn,1,3
                                if rs.eof then
                                        rs.addnew
                                        rs("classname") = classname
                                        rs.update
                                end if
                                classid = rs("classid")
                                rs.close
                                set rs = nothing

                                set rs = server.CreateObject("adodb.recordset")
                                sql = "select * from bt_movie where title in ('" & title & "')"
                                rs.open sql,conn,1,3
                                if rs.eof then
                                        response.Write "<div><font color=blue>写入数据库...</font></div>"
                                        response.Flush()
                                        rs.addnew                       
                                        rs("classid") = classid
                                        rs("title") = title
                                        rs("title2") = title2
                                        rs("intro") = intro
                                        rs("username") = username
                                        rs("filesize") = filesize
                                        rs("url") = url
                                        rs("serverid") = 1
                                        rs("addtime") = addtime
                                        rs("ismake") = 0
                                        rs.update

                                        objxhttp.URL = downurl
                                        objxhttp.saveimage url,False
                                else
                                        response.Write "<div><font color=red>已经存在!</font></div>"
                                end if
                                rs.close
                                set rs = nothing

                                'objxhttp.URL = downurl
                                'objxhttp.saveimage url,False
                        End IF

                Else
                        err.clear
                End IF
                response.Write "-------------------------------------------<br>"
        Next
        set regEx = nothing

       
        response.Write "下一页<br>"
        response.Flush()

        Call NextID()

end if

Sub NextID
        conn.close
        set conn = nothing

        if cint(startid) < cint(overid) and cint(id) < cint(overid) then
                response.Write "<script>location.href='get81bt.asp?action=getdata&classname=" & Request("classname") & "&cid=" & cid & "&startid=" & startid & "&overid=" & overid & "&id="& id + 1 &"'</script>"
        Elseif cint(startid) > cint(overid) and cint(id) > cint(overid) then
                response.Write "<script>location.href='get81bt.asp?action=getdata&classname=" & Request("classname") & "&cid=" & cid & "&startid=" & startid & "&overid=" & overid & "&id="& id - 1 &"'</script>"
        Else
                Response.Write "采集完成!<br>"
                response.End()
        End if
End Sub

%>

</body>
</html>

时间: 2024-08-31 09:40:25

自己做采集程序_小偷/采集的相关文章

用xmlhttp编写web采集程序_小偷/采集

晰带语法着色的版本:http://gwx.showus.net/blog/article.asp?id=229 原创很辛苦,转载请注明原文链接:http://gwx.showus.net/blog/article.asp?id=229 web采集程序?网页抓取程序?小倫程序?不管怎么叫,这种程序应用倒是蛮广的.本文不讨论这种使用这种程序引起的版权或道德问题,只谈这种程序在ASP+VBScript环境下的实现 :-) 预备知识:除了一般的ASP+VBScript的知识外,你还需要了解xmlhttp

自动采集程序_小偷/采集

最近在做一个音乐站,音乐文件嘛...一般是从网上收集..so..写了一段采集程序.  复制代码 代码如下: <%   On Error Resume Next   Const uploadPath = "/uploads/" '文件存放路径   Const allowFileExt = "jpg,wma,swf,gif" '允许被采集的文件类型   'Const allowFileSize = "200"   Function getFil

网站生成静态页面攻略3:防采集策略_小偷/采集

目前防采集的方法有很多种,先介绍一下常见防采集策略方法和它的弊端及采集对策: 一.判断一个IP在一定时间内对本站页面的访问次数,如果明显超过了正常人浏览速度,就拒绝此IP访问     弊端:    1.此方法只适用于动态页面,如:asp\jsp\php等...静态页面无法判断某个IP一定时间访问本站页面的次数.    2.此方法会严重影响搜索引擎蜘蛛对其收录,因为搜索引擎蜘蛛收录时,浏览速度都会比较快而且是多线程.此方法也会拒绝搜索引擎蜘蛛收录站内文件    采集对策:只能放慢采集速度,或者不采

asp实现的7xi音乐网的采集源代码_小偷/采集

共5个文件: 2个是配置文件: 配置文件: cfg.txt '---保存检测ID信息的,第一次采集时设为1,从小到大检测 cfg.asp '---ASP的配置信息,内容如下: 复制代码 代码如下: <%  '''  '''╔=======================================╗  '''┆                                       ┆  '''┆ @系统: 7xi音乐采集系统 Version 2.0    ┆  '''┆ @模块: 配置

小偷&amp;amp;小偷入库&amp;amp;采集入库_小偷/采集

XMLHTTP应用参考  一.使用步骤:  1.创建XMLHTTP对象 //需MSXML4.0支持  2.打开与服务端的连接,同时定义指令发送方式,服务网页(URL)和请求权限等.客户端通过Open命令打开与服务端的服务网页的连接.与普通HTTP指令传送一样,可以用"GET"方法或"POST"方法指向服务端的服务网页.  3.发送指令.  4.等待并接收服务端返回的处理结果.  5.释放XMLHTTP对象  二.XMLHTTP方法:  1.XMLHTTP对象  备注

如何写ASP入库小偷程序_小偷/采集

现在网上流行的小偷程序比较多,有新闻类小偷,音乐小偷,下载小偷,那么它们是如何做的呢,下面我来做个简单介绍,希望对各位站长有所帮助. (一)原理 小偷程序实际上是通过了XML中的XMLHTTP组件调用其它网站上的网页.比如新闻小偷程序,很多都是调用了sina的新闻网页,并且对其中的html进行了一些替换,同时对广告也进行了过滤.用小偷程序的优点有:无须维护网站,因为小偷程序中的数据来自其他网站,它将随着该网站的更新而更新:可以节省服务器资源,一般小偷程序就几个文件,所有网页内容都是来自其他网站.

用正则和xmlHttp实现的asp小偷程序_小偷/采集

复制代码 代码如下: <%  '========================================  class EngineerSearch  '老龙:laolong9999@sina.com  ':模拟XML获取http标记资源(用过之后就知道为什么XML有用:))  '利用引擎搜索(显示引擎信息或其超连接网站上的信息或直接一个指定页面的相关信息,利用正则和xmlHttp,  '程序的使用需要会构造正则)  '----------------------------------

asp alexa查询小偷程序_小偷/采集

<% '为了支持原创,请保留该处注释,谢谢! '作者:草上飞 '获取主域名 Function getDomainUrl(url)     tempurl=replace(url,"http://","")     if instr(tempurl,"/")>0 then         tempurl=left(tempurl,instr(tempurl,"/")-1)     end If     getDoma

用asp获取微软安全更新列表的代码 小偷程序_小偷/采集

复制代码 代码如下: <% Function Bytes2bStr(vin,cSet) Dim BytesStream,StringReturn Set BytesStream = Server.CreateObject("ADODB.Stream") BytesStream.Type = 2 BytesStream.Open BytesStream.WriteText vin BytesStream.Position = 0 BytesStream.CharSet = cSet