youtuber

To delete all the html comment?

5 posts in this topic

#1 ·  Posted

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

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

StringRegExpReplace($html, '(?s)<!--.*?-->', "")  ; remove comments

It's more reliable to compare contents rather than sizes

2 people like this

Share this post


Link to post
Share on other sites

How can I check the size later?

#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

 

Share this post


Link to post
Share on other sites

Check StringLen instead

1 person likes this

Share this post


Link to post
Share on other sites

please help me

#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

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now