Advertisement
AZJIO

Чистка веб страниц, пример

May 8th, 2017
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.91 KB | None | 0 0
  1.  
  2. #NoTrayIcon
  3. #Include <FileOperations.au3>
  4.  
  5. $sep = 'le56tf98'
  6. $aFileList = _FO_FileSearch(@ScriptDir, '*.htm', True, 0, 0)
  7.  
  8. For $i = 1 To $aFileList[0]
  9.  
  10. $sText = FileRead(@ScriptDir & '\' & $aFileList[$i])
  11.  
  12. $sText=StringRegExpReplace($sText, '(?s)<(script|ins|style).+?</\1>', '') ; удалить скрипты, встройки, стили
  13. $sText=StringRegExpReplace($sText, '(?s)<(meta|link) .+?>', '') ; удалить метаданные
  14. $sText=StringReplace($sText, '<head>', '<head>' & @CRLF & '<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">' & @CRLF & '<link type="text/css" rel="stylesheet" href="styles.css">') ; добавить правильные метаданные
  15. ; <meta content="text/html; charset=windows-1251" http-equiv="Content-Type">
  16. ; <link type="text/css" rel="stylesheet" href="styles.css">
  17.  
  18. ; $sText=StringRegExpReplace($sText, '(?s)<script.+?</script>', '') ; удалить скрипты
  19. ; $sText=StringRegExpReplace($sText, '(?s)<ins.+?</ins>', '') ; удалить ins
  20. ; $sText=StringRegExpReplace($sText, '(?s)<style.+?</style>', '') ; удалить style
  21.  
  22.  
  23. $sText=StringRegExpReplace($sText, '(?s)<body>.+?<!-- (studru600x300|studorg600|studnet600) -->', '<body>' & @CRLF & '<!-- ' & $sep & ' -->', 1) ; удалить от начала тела до контента
  24. ; $sText=StringRegExpReplace($sText, '(?s)<!-- ' & $sep & ' -->.+?</center>', '', 1) ; удалить остатки от тега до контента
  25. $sText=StringRegExpReplace($sText, '(?s)<!-- ' & $sep & ' -->.+?</tbody></table><div class="divtext">', '<div class="divtext">', 1) ; удалить остатки от тега до контента
  26. $sText=StringRegExpReplace($sText, '(?s)<!-- ' & $sep & ' -->.+?</td><td valign="top"><h1>', '<h1>', 1) ; удалить остатки от тега до контента
  27. $sText=StringRegExpReplace($sText, '(?s)<!-- (studru580|studnet580) -->.+?</body>', '</body>', 1) ; удалить концовку от контента
  28. $sText = StringRegExpReplace($sText, '(?s)<div class="pagelink">(.+?)</div>', '')
  29.  
  30. ; $sText=StringRegExpReplace($sText, '(?s)<!-- studrurekomend2 -->.+?</body>', '</body>', 1) ; удалить концовку от контента
  31. ; $sText=StringRegExpReplace($sText, '(?s)<!-- studsurekomed -->.+?</body>', '</body>', 1) ; удалить концовку от контента
  32.  
  33. ; $sText=StringRegExpReplace($sText, '(?s)<p>\r\n<a href="http://studopedia.su/.+?</span></a>\t</p>', '', 1)
  34. ; $sText=StringRegExpReplace($sText, '(?s)<!-- RotaBan.ru Ad Code -->.+?<!-- END RotaBan.ru Ad Code -->', '')
  35.  
  36.  
  37. ; $aSample = [2, 'RotaBan.ru Ad Code', 'RotaBan.ru Zone']
  38. ; For $i = 1 To $aSample[0]
  39.     ; $sText=StringRegExpReplace($sText, '(?s)<!-- ' & $aSample[$i] & ' -->.+?<!-- END ' & $aSample[$i] & ' -->', '')
  40. ; Next
  41.  
  42.  
  43. $hFile = FileOpen(@ScriptDir & '\1' & $aFileList[$i], 2)
  44. FileWrite($hFile, $sText)
  45. FileClose($hFile)
  46. Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement