<% 这里能截取网页的内容,但是不能批量采集。我想问一下,那个正则表达式怎么写才能搞定。
url="http://www.16k.cn/Html/Book/2/2101/index.html"
Ht=getHTTPPage(url)
St="<title>"
En="- 16K小说网 - 16K小说网-手机电子书"
c_st="BookText"
c_en="LinkMenu"
qq="更多免费精彩小说尽在翠云居(www.cuiyunju.cn),本小说由(会员:暗夜上传)有兴趣的书友,请加QQ群:54319681(注明:以书会友)"
title=Instrstring(Ht,St,En)
content=Instrstring(Ht,c_st,c_en)
/////////////////////////////////////////////////////////////////////////////////////////////
就是这一段。
Function body(wstr,start,over)
Set xiaoqi = New Regexp'设置配置对象
xiaoqi.IgnoreCase = True'忽略大小写
xiaoqi.Global = True'设置为全文搜索
xiaoqi.Pattern = (content,"<li> <a href=\"([^\"]*)\" title=\"更新时间:[^\"]*\">[^<]*</a> </li>");'正则表达式
Set Matches =xiaoqi.Execute(wstr)'开始执行配置
set xiaoqi=nothing
body=""
For Each Match in Matches
body=body&Match.Value '循环匹配
Next
End Function
//////////////////////////////////////////////////////////////////////////////////////////////
%>
<%
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 '检查是否完成,readystate值为4说明载入完毕
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312") '把Http.responseBody 内容作GB2312转换
set http=nothing '释放变量
If Err.number<>0 then 'err.Number<>0表示有错误,清除错误
Response.Write "<p align='center'><font color='red'><b>服务器获取文件内容出错</b></font></p>"
Err.Clear
End If
End FunctionFunction 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 '设置流对象的起始位置为0,也就是说不过滤,如果设置为2则过滤掉一个控制字符
objstream.Type = 2
objstream.Charset = Cset '转换成GB2312格式
BytesToBstr = objstream.ReadText '把流对象的内容保存在这个参数里
objstream.Close
set objstream = nothing
End Function
function Instrstring(Html,Sta,Enn)
strhtml=Html
s1=instr(strhtml,Sta)+len(Sta)
s2=instr(s1,strhtml,Enn,0)
Instrstring=mid(strhtml,s1,s2-s1)
end function%>
url="http://www.16k.cn/Html/Book/2/2101/index.html"
Ht=getHTTPPage(url)
St="<title>"
En="- 16K小说网 - 16K小说网-手机电子书"
c_st="BookText"
c_en="LinkMenu"
qq="更多免费精彩小说尽在翠云居(www.cuiyunju.cn),本小说由(会员:暗夜上传)有兴趣的书友,请加QQ群:54319681(注明:以书会友)"
title=Instrstring(Ht,St,En)
content=Instrstring(Ht,c_st,c_en)
/////////////////////////////////////////////////////////////////////////////////////////////
就是这一段。
Function body(wstr,start,over)
Set xiaoqi = New Regexp'设置配置对象
xiaoqi.IgnoreCase = True'忽略大小写
xiaoqi.Global = True'设置为全文搜索
xiaoqi.Pattern = (content,"<li> <a href=\"([^\"]*)\" title=\"更新时间:[^\"]*\">[^<]*</a> </li>");'正则表达式
Set Matches =xiaoqi.Execute(wstr)'开始执行配置
set xiaoqi=nothing
body=""
For Each Match in Matches
body=body&Match.Value '循环匹配
Next
End Function
//////////////////////////////////////////////////////////////////////////////////////////////
%>
<%
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 '检查是否完成,readystate值为4说明载入完毕
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312") '把Http.responseBody 内容作GB2312转换
set http=nothing '释放变量
If Err.number<>0 then 'err.Number<>0表示有错误,清除错误
Response.Write "<p align='center'><font color='red'><b>服务器获取文件内容出错</b></font></p>"
Err.Clear
End If
End FunctionFunction 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 '设置流对象的起始位置为0,也就是说不过滤,如果设置为2则过滤掉一个控制字符
objstream.Type = 2
objstream.Charset = Cset '转换成GB2312格式
BytesToBstr = objstream.ReadText '把流对象的内容保存在这个参数里
objstream.Close
set objstream = nothing
End Function
function Instrstring(Html,Sta,Enn)
strhtml=Html
s1=instr(strhtml,Sta)+len(Sta)
s2=instr(s1,strhtml,Enn,0)
Instrstring=mid(strhtml,s1,s2-s1)
end function%>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货