html頁(yè)面一般都會(huì)指定一個(gè)編碼,如何獲取到是處理html頁(yè)面的第一步,因?yàn)殄e(cuò)誤的編碼必然帶來(lái)后面處理的問(wèn)題。這里我用python的正則表達(dá)式寫了個(gè):
import rea = ["<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'
新聞熱點(diǎn)
疑難解答
圖片精選