XMLHTTP批量抓取远程资料<html> 
XMLHTTP批量抓取远程资料
<head> 
XMLHTTP批量抓取远程资料
<title>AUTOGET</title> 
XMLHTTP批量抓取远程资料
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
XMLHTTP批量抓取远程资料
</head> 
XMLHTTP批量抓取远程资料
<body bgcolor="#FFFFFF" style="font-family:Arial;font-size:12px"> 
XMLHTTP批量抓取远程资料
<
XMLHTTP批量抓取远程资料
'================================================= 
XMLHTTP批量抓取远程资料'
FileName: Getit.Asp 
XMLHTTP批量抓取远程资料'
Intro : Auto Get Data From Remote WebSite 
XMLHTTP批量抓取远程资料'
Author: Babyt(阿泰) 
XMLHTTP批量抓取远程资料'
URL: http://www.cnblogs.com/babyt/ 
XMLHTTP批量抓取远程资料'
CreateAt: 2002-02  LastUpdate:2004-09 
XMLHTTP批量抓取远程资料'
DB Table : data 
XMLHTTP批量抓取远程资料'
Table Field: 
XMLHTTP批量抓取远程资料'
 UID -> Long -> Keep ID Of the pages 
XMLHTTP批量抓取远程资料'
 UContent -> Text -> Keep Content Of the Pages(HTML) 
XMLHTTP批量抓取远程资料'
================================================= 
XMLHTTP批量抓取远程资料

XMLHTTP批量抓取远程资料Server.ScriptTimeout
=5000
XMLHTTP批量抓取远程资料
XMLHTTP批量抓取远程资料
'on error resume next 
XMLHTTP批量抓取远程资料
Set conn = Server.CreateObject("ADODB.Connection"
XMLHTTP批量抓取远程资料conn.open 
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("getit.mdb"
XMLHTTP批量抓取远程资料
Set rs = Server.CreateObject("ADODB.Recordset"
XMLHTTP批量抓取远程资料sql
="select * from data" 
XMLHTTP批量抓取远程资料rs.open sql,conn,
1,3 
XMLHTTP批量抓取远程资料
XMLHTTP批量抓取远程资料
Dim comeFrom,myErr,myCount
XMLHTTP批量抓取远程资料
XMLHTTP批量抓取远程资料
'======================================================== 
XMLHTTP批量抓取远程资料
comeFrom="http://www.xxx.com/U.asp?ID=" 
XMLHTTP批量抓取远程资料myErr1
="该资料不存在" 
XMLHTTP批量抓取远程资料myErr2
="该资料已隐藏" 
XMLHTTP批量抓取远程资料
'======================================================== 
XMLHTTP批量抓取远程资料

XMLHTTP批量抓取远程资料
'*************************************************************** 
XMLHTTP批量抓取远程资料'
 只需要更改这里 i 的始点intMin和终点intMax,设定一次运行的区间intStep 
XMLHTTP批量抓取远程资料'
 每次区间设置成5万左右。估计要两个多小时。期间不需要人工干预 
XMLHTTP批量抓取远程资料'
**************************************************************** 
XMLHTTP批量抓取远程资料
intMin=0 
XMLHTTP批量抓取远程资料intMax
=10000 
XMLHTTP批量抓取远程资料
'设定步长 
XMLHTTP批量抓取远程资料
intStep=100 
XMLHTTP批量抓取远程资料
XMLHTTP批量抓取远程资料
'========================================================== 
XMLHTTP批量抓取远程资料'
以下代码不要更改 
XMLHTTP批量抓取远程资料'
========================================================== 
XMLHTTP批量抓取远程资料
Call GetPart (intMin) 
XMLHTTP批量抓取远程资料Response.write 
"已经转换完成" & intMin & "~~" & intMax & "之间的数据" 
XMLHTTP批量抓取远程资料rs.close 
XMLHTTP批量抓取远程资料
Set rs=Nothing 
XMLHTTP批量抓取远程资料conn.Close 
XMLHTTP批量抓取远程资料
set conn=nothing 
XMLHTTP批量抓取远程资料%
> 
XMLHTTP批量抓取远程资料
</body> 
XMLHTTP批量抓取远程资料
</html> 
XMLHTTP批量抓取远程资料
<
XMLHTTP批量抓取远程资料
'使用XMLHTTP抓取地址并进次内容处理 
XMLHTTP批量抓取远程资料
Function GetBody(Url) 
XMLHTTP批量抓取远程资料        
Dim objXML 
XMLHTTP批量抓取远程资料        
On Error Resume Next 
XMLHTTP批量抓取远程资料        
Set objXML = CreateObject("Microsoft.XMLHTTP"
XMLHTTP批量抓取远程资料        
With objXML 
XMLHTTP批量抓取远程资料        .Open 
"Get", Url, False"""" 
XMLHTTP批量抓取远程资料        .Send 
XMLHTTP批量抓取远程资料        GetBody 
= .ResponseBody 
XMLHTTP批量抓取远程资料        
End With 
XMLHTTP批量抓取远程资料        GetBody
=BytesToBstr(GetBody,"GB2312"
XMLHTTP批量抓取远程资料        
Set objXML = Nothing 
XMLHTTP批量抓取远程资料
End Function 
XMLHTTP批量抓取远程资料
'使用Adodb.Stream处理二进制数据 
XMLHTTP批量抓取远程资料
Function BytesToBstr(strBody,CodeBase) 
XMLHTTP批量抓取远程资料        
dim objStream 
XMLHTTP批量抓取远程资料        
set objStream = Server.CreateObject("Adodb.Stream"
XMLHTTP批量抓取远程资料        objStream.Type 
= 1 
XMLHTTP批量抓取远程资料        objStream.Mode 
=3 
XMLHTTP批量抓取远程资料        objStream.Open 
XMLHTTP批量抓取远程资料        objStream.Write strBody 
XMLHTTP批量抓取远程资料        objStream.Position 
= 0 
XMLHTTP批量抓取远程资料        objStream.Type 
= 2 
XMLHTTP批量抓取远程资料        objStream.Charset 
= CodeBase 
XMLHTTP批量抓取远程资料        BytesToBstr 
= objStream.ReadText 
XMLHTTP批量抓取远程资料        objStream.Close 
XMLHTTP批量抓取远程资料        
set objStream = nothing 
XMLHTTP批量抓取远程资料
End Function 
XMLHTTP批量抓取远程资料
'主函数 
XMLHTTP批量抓取远程资料
Function GetPart(iStart) 
XMLHTTP批量抓取远程资料 
Dim iGo 
XMLHTTP批量抓取远程资料 time1
=timer() 
XMLHTTP批量抓取远程资料 myCount
=0 
XMLHTTP批量抓取远程资料 
For iGo=iStart To iStart+intStep 
XMLHTTP批量抓取远程资料  
If iGo<=intMax Then 
XMLHTTP批量抓取远程资料   Response.
Execute comeFrom & iGo 
XMLHTTP批量抓取远程资料   
'进行简单的数据处理 
XMLHTTP批量抓取远程资料
   content = GetBody(comeFrom & iGo ) 
XMLHTTP批量抓取远程资料   content 
= Replace(content,chr(34),""
XMLHTTP批量抓取远程资料   
If  instr(content,myErr1) OR instr(content,myErr2)  Then 
XMLHTTP批量抓取远程资料    
'跳过错误信息 
XMLHTTP批量抓取远程资料
   Else  
XMLHTTP批量抓取远程资料    
'写入数据库 
XMLHTTP批量抓取远程资料
    rs.AddNew 
XMLHTTP批量抓取远程资料    rs(
"UID")=iGo 
XMLHTTP批量抓取远程资料    
'********************************  
XMLHTTP批量抓取远程资料
    rs("UContent")=Replace(content,"",chr(34)) 
XMLHTTP批量抓取远程资料    
'********************************* 
XMLHTTP批量抓取远程资料
    rs.update 
XMLHTTP批量抓取远程资料    myCount
=myCount+1 
XMLHTTP批量抓取远程资料    Response.Write iGo 
& "<BR>" 
XMLHTTP批量抓取远程资料    Response.Flush 
XMLHTTP批量抓取远程资料   
End If   
XMLHTTP批量抓取远程资料  
Else 
XMLHTTP批量抓取远程资料   Response.write 
"<font color=red>成功抓取"&myCount&"条记录," 
XMLHTTP批量抓取远程资料   time2
=timer() 
XMLHTTP批量抓取远程资料   Response.write 
"耗时:" & Int(FormatNumber((time2-time1),3)) & " 秒</font><BR>" 
XMLHTTP批量抓取远程资料   Response.Flush 
XMLHTTP批量抓取远程资料   
Exit Function 
XMLHTTP批量抓取远程资料  
End If 
XMLHTTP批量抓取远程资料 
Next 
XMLHTTP批量抓取远程资料 Response.write 
"<font color=red>成功抓取"&myCount&"条记录," 
XMLHTTP批量抓取远程资料 time2
=timer() 
XMLHTTP批量抓取远程资料 Response.write 
"耗时:" & CInt(FormatNumber((time2-time1),3)) & " 秒</font><BR>" 
XMLHTTP批量抓取远程资料 Response.Flush 
XMLHTTP批量抓取远程资料 
'递归 
XMLHTTP批量抓取远程资料
 GetPart(iGo+1
XMLHTTP批量抓取远程资料
End Function
XMLHTTP批量抓取远程资料%
> 
XMLHTTP批量抓取远程资料 

XMLHTTP批量抓取远程资料 

相关文章:

  • 2022-12-23
  • 2021-08-15
  • 2022-01-19
  • 2021-07-21
  • 2021-06-23
  • 2021-12-26
猜你喜欢
  • 2021-10-03
  • 2021-11-24
  • 2021-06-26
  • 2021-12-03
  • 2021-11-05
相关资源
相似解决方案