存档

2009年1月4日 的存档

今天,公司的网站百度还没有收录,郁闷。
把名片系统改成生成静态页的吧,一看逻辑。哎呦,真不知道以前怎么写的,有二三十个IF判断,也就是可能有二三十个结果。在分析太麻烦了。
以前写小偷的时候,用到了XMLHTTP,现在也许用XMLHTTP直接就可以。。。
呵呵,思路有了,实现方法也就简单了
第一步,通过分析,名片的内容格式为QY-Card.asp?ComID={记录ID},读取数据库,获取记录ID,每页生成40条,从第一页到最后一页,用JS的SetTimeout来设定一秒后调到下一页。
第二步,因为小偷是现成的代码,URL有了,所以直接写一个ToFile的函数,然后调用即可。
函数代码如下(tofile.asp):

< %
set fso=server.createobject("scripting.filesystemobject")
 
Sub SaveHtml(url,id)
file=server.mappath("/cards/"&id&".html")
if not fso.fileexists(file) then
set fto=fso.createTextfile(file)
else
set fto=fso.opentextfile(file,2)
end if
fto.write getHTTPPage(url)
fto.close
set fto=nothing
End Sub
%>

小偷代码如下(thief.asp)

< %
function getHTTPPage(url)
dim Http
set Http=createobject("MSXML2.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 err.Clear
end function
 
Function BytesToBstr(body,Cset)
dim objstream
set objstream = 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
%>

第一步的ASP代码就简单了,无非就是一个分页函数。代码如下(后台数据库连接文件为conn_admin.asp,权限检测为cook.asp):

< %dbdns="../../"%>
<!–#include file="../../inc/conn_admin.asp"–>
<!–#include file="../cook.asp"–>
<!–#include file="Thief.asp"–>
<!–#include file="ToFile.asp"–>
< %
set [...]

一 4th, 2009 | Filed under ASP, Experience(经验)
标签: