créer un site internet




 
 

Awk : calcul la taille d'une page html

Ce script vous donnera la taille totale d'une page html en tenant compte des images, des scripts et des feuilles de style inclus.

C'est très facile à utiliser, il suffit de taper le nom du script suivi du nom du fichier html
#!/bin/awk -f

BEGIN {
  RS="<"
}


# <IMG SRC ...
/^(I|i)(m|M)(g|G) .*(s|S)(r|R)(C|c)/ {
  sub(/^(I|i)(m|M)(g|G) .*(s|S)(r|R)(C|c) *="?/,"",$0)
  match($0,/[^" ]+("| )?/)
  image = substr($0,RSTART,RLENGTH-1)
  if ( image ~ /^http/ )
    next
  if ( length(image ) < 5 )
    next
  images[image]=1
  next
}

# <SCRIPT SRC...
/^(s|S)(C|c)(r|R)(I|i)(P|p)(T|t) .*(s|S)(r|R)(C|c)/ {
  sub(/^(s|S)(C|c)(r|R)(I|i)(P|p)(T|t) .*(s|S)(r|R)(C|c) *="?/,"",$0)
  match($0,/[^" ]+("| )?/)
  image = substr($0,RSTART,RLENGTH-1)
  if ( image ~ /^http/ )
    next
  if ( length(image ) < 2 )
    next
  images[image]=1
  next
}

#CSS
/^(L|l)(I|i)(N|n)(K|k) .*(H|h)(r|R)(E|e)(F|f)/ {
  sub(/^(L|l)(I|i)(N|n)(K|k) .*(H|h)(r|R)(E|e)(F|f) *="?/,"",$0)
  match($0,/[^" ]+("| )?/)
  image = substr($0,RSTART,RLENGTH-1)
  if ( image ~ /^http/ )
    next
  if ( length(image ) < 2 )
    next
  images[image]=1
  next
}

END {
  total=0
  images[FILENAME]=1
  for ( i in images  )
  {
    command = "wc -c "i
    command  | getline
    print i " " $1
    total += $1
  }
  print "_______________"
  print "total = "total

}


A propos - Contact - Réalisé avec Youhp3 v3.8 - v7.0 béta
Mentions Légales - CNIL n°800914
© AffilZEN 1998 - 2008 :: Auteur Nicolas : CV - NiKoZEN : Référencement
Part. : Créer un site, Creer son site