简单析取html文件实例
【打印文章】
用offline下载了一些小说,放在局域网上,想用自己设计的页面显示,内容放在一个table中,如果取全部html,会有效果问题,因此只取<body ....> </body>之间的,代码如下:
<%
dim filepath
filepath=replace(Request.QueryString ("tar"),chr(34),"")
filepath=Server.MapPath(filepath)
set x=server.CreateObject ("Scripting.FileSystemObject")
set y=x.OpenTextFile (filepath,1,false)
result=y.readall()
y.close
set y=nothing
set x=nothing
'end if
result=lcase(result)
''''''''''''''''''''''''
result=mid(result,instr(result,"<body"),instr(result,"</body>"))
result=replace(result,"</body>","")
result=mid(result,instr(result,">")+1)
''''''''''''''''''''''''
''以下,把所有打开文件中的连接转换
''<a href="c.html">---><a href="show.asp?tar=c.html">
'' 或---><a href="show.asp?tar=a/b/c.html">
if instr(request.querystring("tar"),"/")<>0 then
dim temp
temp=left(request.querystring("tar"),instrrev(request.querystring("tar"),"/"))
result=replace(result,"href=" & chr(34),"href=" & chr(34) & "show.asp?tar=" & temp)
else
''
result=replace(result,"href=" & chr(34),"href=" & chr(34) & "show.asp?tar=")
end if
Response.Write "<pre>" & result & "</pre>"
%>
<%
dim filepath
filepath=replace(Request.QueryString ("tar"),chr(34),"")
filepath=Server.MapPath(filepath)
set x=server.CreateObject ("Scripting.FileSystemObject")
set y=x.OpenTextFile (filepath,1,false)
result=y.readall()
y.close
set y=nothing
set x=nothing
'end if
result=lcase(result)
''''''''''''''''''''''''
result=mid(result,instr(result,"<body"),instr(result,"</body>"))
result=replace(result,"</body>","")
result=mid(result,instr(result,">")+1)
''''''''''''''''''''''''
''以下,把所有打开文件中的连接转换
''<a href="c.html">---><a href="show.asp?tar=c.html">
'' 或---><a href="show.asp?tar=a/b/c.html">
if instr(request.querystring("tar"),"/")<>0 then
dim temp
temp=left(request.querystring("tar"),instrrev(request.querystring("tar"),"/"))
result=replace(result,"href=" & chr(34),"href=" & chr(34) & "show.asp?tar=" & temp)
else
''
result=replace(result,"href=" & chr(34),"href=" & chr(34) & "show.asp?tar=")
end if
Response.Write "<pre>" & result & "</pre>"
%>
本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )
【编程爱好者论坛】