youtuber Posted October 9, 2016 Share Posted October 9, 2016 To find out how all the html comments are deleted and size. ? #include <Array.au3> #include <String.au3> #include <File.au3> #include <Inet.au3> $aSiteUrl = "https://www.autoitscript.com/forum/index.php" For $i = 1 To UBound($aSiteUrl) $sitenamestr = StringRegExp($aSiteUrl[$i], 'https?://(?:www.)?([^.]+)', 3) $sitenames = $sitenamestr[0] $downloadtemp = @ScriptDir & '\older\' & $sitenames & '.php' $newdir = @ScriptDir & '\newer\' & $sitenames & '.php' $inetgetsites = InetGet($aSiteUrl[$i], $downloadtemp, 1, 1) $webfileread = FileRead($downloadtemp[$i]) $Searchhtmlcomment = StringRegExp($webfileread[$i],'\<!--(.+?)-->',1) If StringInStr($Searchhtmlcomment[$i], "<!--") Then $htmlcommentDelete = StringRegExpReplace($webfileread[$i], "<[\/\!].*?>", "") $ext = $sitenames & '.php' $array = _FileListToArray($downloadtemp, $ext, $FLTA_FILES) For $i = 1 To $array[0] FileCopy($downloadtemp & "\" & $array[$i], $newdir, $FC_OVERWRITE) Next EndIf $sizecontrol = FileGetSize($downloadtemp) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sizecontrol[$i] = ' & $sizecontrol[$i] & @CRLF & '>Error code: ' & @error & @CRLF) Next Link to comment Share on other sites More sharing options...
mikell Posted October 9, 2016 Share Posted October 9, 2016 StringRegExpReplace($html, '(?s)<!--.*?-->', "") ; remove comments It's more reliable to compare contents rather than sizes trancexx and youtuber 2 Link to comment Share on other sites More sharing options...
youtuber Posted October 10, 2016 Author Share Posted October 10, 2016 How can I check the size later? expandcollapse popup#include <File.au3> #include <Array.au3> #include <Inet.au3> #include <String.au3> Global $readlist = FileRead(@ScriptDir & "\sitelist.txt") _firstdownloaded() Func _firstdownloaded() Local $olddir = @ScriptDir & '\old\' Local $sitelisturl = StringSplit(StringStripCR($readlist), @LF) For $i = 1 To UBound($sitelisturl) - 1 $sitenamestr = StringRegExp($sitelisturl[$i], 'https?://(?:www.)?([^.]+)', 3) $sitenames = $sitenamestr[0] ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sitenames = ' & $sitenames & @CRLF & '>Error code: ' & @error & @CRLF) $downloadtemp = @ScriptDir & '\old\' & $sitenames & '.xml' If FileExists(@ScriptDir & "\old" & $downloadtemp) Then $inetgetsites = InetGet($sitelisturl[$i], $downloadtemp, 1, 1) Else DirCreate(@ScriptDir & "\" & "old") $inetgetsites = InetGet($sitelisturl[$i], $downloadtemp, 1, 1) EndIf $olderSize = FileGetSize($downloadtemp) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : olderSize = ' & $olderSize & @CRLF & '>Error code: ' & @error & @CRLF) $ext = $sitenames & '.xml' $array = _FileListToArray($olddir, $ext, $FLTA_FILES) For $i = 1 To $array[0] $openFile = FileOpen($olddir & $array[$i], 1) $sFileRead = FileRead($openFile) If StringInStr($sFileRead, "<!--") Then $htmlcommentDelete = StringRegExpReplace($sFileRead[$i], '(?s)<!--.*?-->', "") FileClose($openFile[$i]) Else $newerSize = FileGetSize($downloadtemp) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $newerSize = ' & $newerSize & @CRLF & '>Error code: ' & @error & @CRLF) EndIf Next Next EndFunc Link to comment Share on other sites More sharing options...
mikell Posted October 10, 2016 Share Posted October 10, 2016 Check StringLen instead youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted October 10, 2016 Author Share Posted October 10, 2016 please help me expandcollapse popup#include <File.au3> #include <Array.au3> #include <Inet.au3> #include <String.au3> Global $readlist = FileRead(@ScriptDir & "\sitelist.txt") _firstdownloaded() Func _firstdownloaded() Local $olddir = @ScriptDir & '\old\' Local $sitelisturl = StringSplit(StringStripCR($readlist), @LF) For $i = 1 To UBound($sitelisturl) - 1 $sitenamestr = StringRegExp($sitelisturl[$i], 'https?://(?:www.)?([^.]+)', 3) $sitenames = $sitenamestr[0] ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sitenames = ' & $sitenames & @CRLF & '>Error code: ' & @error & @CRLF) $downloadtemp = @ScriptDir & '\old\' & $sitenames & '.xml' If FileExists(@ScriptDir & "\old" & $downloadtemp) Then $inetgetsites = InetGet($sitelisturl[$i], $downloadtemp, 1, 1) Else DirCreate(@ScriptDir & "\" & "old") $inetgetsites = InetGet($sitelisturl[$i], $downloadtemp, 1, 1) EndIf $ext = $sitenames & '.xml' $array = _FileListToArray($olddir, $ext, $FLTA_FILES) For $i = 1 To $array[0] $openFile = FileOpen($olddir & $array[$i], 1) $sFileRead = FileRead($openFile) If StringInStr($sFileRead, "<!--") Then $htmlcommentDelete = StringRegExpReplace($sFileRead[$i], '(?s)<!--.*?-->', "") $newerLine = StringLen($htmlcommentDelete) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $newerLine = ' & $newerLine & @CRLF & '>Error code: ' & @error & @CRLF) FileClose($openFile[$i]) EndIf Next Next EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now