HTML pages typically specify an encoding, and how to get to the first step in processing an HTML page, because the wrong encoding inevitably brings the problem to be dealt with later. Here I wrote a regular expression of Python:
Import re
a = ["<meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 "/>",
' <meta Http-equiv=content-type content= "text/html;charset=gb2312" > ',
' <meta http-equiv= ' Content-type ' content= "Text/html; Charset=iso-8859-1 ">", "
<meta http-equiv=" Content-type "content=" text/html, charset=gb2312 "/>",
"<meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 "/> '", "
<meta http-equiv=" Content-type "content=" text/html "charset=gb2312", '/> ',
' <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/> '
]
b =" <meta[]+http-equiv=["']?content-type[" ']?[] +content=["']?text/html; []*charset= ([0-9-a-za-z]+) ["]?"
b = Re.compile (b, re. IGNORECASE)
for Ax in a:
r1 = b.search (ax)
if R1:
print r1.group ()
print R1.group (1), Len ( R1.group ())
else:
print ' not match '