[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[网络工具] 批处理+VBS骗术网正文提取

get-html-news.bat
  1. @echo off&&setlocal enabledelayedexpansion
  2. set line=1
  3. set line0=1
  4. set count=0
  5. for /f "usebackq tokens=*" %%j in (`find /N  "正文begin" %1`) do (
  6. if !line! NEQ 1 (ver>nul&&set/a line=line+1) else (set str1=%%j)
  7. )
  8. set /a line=!str1:~1,3!-1
  9. if !line! equ 1 (
  10.        echo                              文件没有正文
  11.        ping -n 2 127.0.0.1 >nul&exit
  12.                  )
  13. ::echo !line!
  14. ::pause>nul
  15. for /f "usebackq tokens=*" %%j in (`find /N  "正文end" %1`) do (
  16. if !line0! NEQ 1 (ver>nul&&set/a line0=line0+1) else (set str1=%%j)
  17. )
  18. set /a line0=!str1:~1,3!-1
  19. ::echo !line0!
  20. ::pause>nul
  21. set path=%~dp1
  22. set name=%~n1
  23. set filename=%name:~-3,2%
  24. set count=!line!
  25. set str=
  26. for /f "usebackq skip=%line% tokens=*" %%i in (%1) do (
  27. set str=%%i
  28. set /a count=count+1
  29. if !count! equ !line0! (
  30. echo                  正文提取完成
  31. for /l %%i in (1,1,100000) do ver>nul&start html.vbs !path!!filename!.txt&exit) else (
  32.     if "!str!"=="" (ver>nul) else (
  33.               echo !str!>>!path!tmp.txt
  34.                     )
  35.          )
  36. )
复制代码
html.vbs 如下:
  1. dim File
  2. dim flag    '判断是标题还是正文
  3. flag=0
  4. Set FSO=CreateObject("Scripting.FileSystemObject")   
  5. File=FSO.GetParentFolderName(WScript.ScriptFullName)&"\tmp.txt"
  6. If File<>"" And FSO.FileExists(File) Then
  7.   Set thefile=FSO.OpenTextFile(File,1,True)
  8. Else
  9.   Set thefile=FSO.OpenTextFile(FSO.GetParentFolderName(WScript.ScriptFullName)&"\tmp.txt",1,True)
  10. End If
  11. Set fin=FSO.OpenTextFile(WScript.Arguments(0),2,True)
  12. Do While theFile.AtEndOfstream <> True
  13.    
  14.   
  15.   if flag=0 then
  16.   line=theFile.Readline
  17.   rv=title("articletitle.*[^</td>]",line)
  18.   if rv="" then
  19.   flag=0
  20.   else
  21.   rv=mid(rv,15,len(rv)-14)
  22.   fin.WriteLine("                             "& rv)
  23.   flag=1
  24.   end if
  25.   else
  26.    if rv="" then
  27.    flag=1
  28.    else
  29.    line=theFile.Readline
  30.    code=code+line
  31.    end if
  32. end if
  33. Loop
  34.    rv=zhengwen(code)
  35.    hangshu=len(rv)/40+1 '确定每一行的字数
  36.    for i=1 to hangshu
  37.    fin.WriteLine(mid(rv,(i-1)*(40)+1,40))
  38.    next
  39. thefile.close()
  40. fin.close()
  41. FSO.deletefile(FSO.GetParentFolderName(WScript.ScriptFullName)&"\tmp.txt")
  42. set thefile=nothing
  43. set fin=nothing
  44. Function title(patrn, strng)
  45. Dim regEx, Match, Matches
  46. Set regEx = New RegExp
  47. regEx.Pattern = patrn
  48. regEx.IgnoreCase =True
  49. regEx.Global =True
  50. Set Matches =regEx.Execute(strng)
  51. For Each Match in Matches
  52. title=match.value
  53. next
  54. Set objRegExp = Nothing
  55. End Function
  56. Function zhengwen(strHTML)
  57. Dim regEx, Match, Matches
  58. Set regEx = New RegExp
  59. regEx.IgnoreCase =True
  60. regEx.Global =True  
  61. regEx.Pattern ="<ul.+?ul>"
  62. Set Matches =regEx.Execute(strHTML)
  63. For Each Match in Matches
  64. out=match.value
  65. next
  66. regEx.Pattern ="<.+?>"
  67. out=regEx.replace(out,"")
  68. regEx.Pattern =" "      
  69. out=regEx.replace(out,"")
  70. regEx.Pattern ="\|.+?\|"
  71. out=regEx.replace(out,"")
  72. regEx.Pattern =".?\[.+?\].?"
  73. out=regEx.replace(out,"")
  74. regEx.Pattern ="3骗}术.*?>"
  75. out=regEx.replace(out,"")
  76. regEx.Pattern ="6骗1术%网"
  77. out=regEx.replace(out,"")
  78. regEx.Pattern ="\?骗\+术"
  79. out=regEx.replace(out,"")
  80. zhengwen=out
  81. End Function
复制代码
介绍:本来是想用纯批写的,但是由于自己不是很懂findstr  无法用纯批写
最后选用了vbs中的正则表达式.
程序使用介绍,直接将迅雷下载的文件拖放到get-html-news.bat上即可
本批处理现今只能处理单个的文件。其实只要获得文件夹下文件列表即可实现批量处理。
还有一处在利用for 读文件时,有时会有一些问题,可能是由于一些特殊字符造成。
程序还有较多漏洞希望大家一起改进.

返回列表