当前位置: 首页 > news >正文

做自己的首席安全官的网站建营销型网站

做自己的首席安全官的网站,建营销型网站,西宁网站建设官网,wordpress架设编码规范化 在计算机中#xff0c;我们需要将字符与字节序列之间建立起映射关系#xff0c;这个过程被称为编码。有许多不同的编码方式#xff0c;例如 ASCII、UTF-8、UTF-16 和 GBK 等。这些编码方式会将每个字符编码为一个或多个字节#xff0c;以便于在计算机、网络和其…编码规范化 在计算机中我们需要将字符与字节序列之间建立起映射关系这个过程被称为编码。有许多不同的编码方式例如 ASCII、UTF-8、UTF-16 和 GBK 等。这些编码方式会将每个字符编码为一个或多个字节以便于在计算机、网络和其他设备之间进行存储和传输。 Unicode是一种字符集它为每个字符、符号和表情符分配了一个唯一的码位整数它与许多不同的编码方式结合使用。 编解码 英文数据处理特点首字母大写、词与词间用空格分隔、标点符号与词汇写在一起。 中文数据处理与英文不同没有分词所有词之间没有空格 数据处理的目的在于去除脏数据保留干净可用的部分其中编解码是关键环节。 chr() 是 Python 中的一个内置函数它将一个整数Unicode 码位转换为一个字符 chr(a) achr() 函数的逆函数是 ord()它将一个字符长度为 1 的字符串转换为一个整数Unicode 码位 ord(A) 65编码标准 用不同的编码标准会得到不同的字节序列尽管在文本中显示的是同一个字 可.encode(gbk) b\xbf\xc9可.encode(utf-8) b\xe5\x8f\xafa 可.encode(utf-8)b 可.encode(gbk)a b False将其解码后与Python默认的Unicode字符集对应 a.decode(utf-8) 可 True1.处理编解码错误 检测文本是否以UTF-8编码。 #encoding: utf-8import sysdef handle(sl1,sl2,rl1,rl2):ens \n.encode(utf-8)with open(sl1,rb) as fs1,open(sl2,rb) as fs2,open(rl1,wb) as fr1,open(rl2,wb) as fr2:for l1, l2 in zip(fs1,fs2): #按行读t1 ,t2 l1.strip(), l2.strip() #去除每行首、尾的回车、制表、空格if t1 and t2: #如果t1、t2 非空try: #解码t1, t2 t1.decode(utf-8), t2.decode(utf-8)except Exception as e: #decode方法抛出异常说明原文不满足u8编码t1 t2 #异常置空if t1 and t2: #以U8再编码fr1.write(t1.encode(utf-8))fr1.write(ens) #将strip()过的回车添加上将行隔开fr2.write(t2.encode(utf-8))fr2.write(ens)if __name____main__:handle(*sys.argv[1:]) 执行后在命令行使用wc -l fname 查看行数统计因编解码错误而被丢掉的行。 2.编码统一 HTML数据清洗 在网页上爬取的数据编码方式可能不同例如使用Python的html库 import htmlhtml.escape() amp;escape()函数的逆函数是unescape()会将HTML标记转化为Unicode字符。 html.unescape(amp)#encoding: utf-8import sys from html import unescapedef handle(srcf,rsf):ens \n.encode(utf-8)with open(srcf,rb) as frd, open(rsf,wb) as fwrt:for line in frd:tmp line.strip()if tmp:tmp unescape(tmp.decode(utf-8))fwrt.write(tmp.encode(utf-8))fwrt.write(ens)if __name____main__:handle(*sys.argv[1:])md5sum 是一个 Linux 和 Unix 操作系统中的命令行工具用于计算和验证文件的 MD5 校验和。MD5 是一种哈希函数它可以将任意长度的数据转换为一个固定长度的哈希值。 通过对比数据清洗前后的md5sum值可以看到文件是否发生变化。 全角转为半角 全角字符与半角字符的unicode编码不一致 a ab a b Falseord(a),ord(b) (97, 65345)他们的差值即是95345-9765248 chr(ord(b)-65248) a Truefull2half.py #encoding: utf-8 import sysdef D2S(istr): #全角转半角rs []for c in istr:num ord(c)if num 12288:rs.append( ) #如果检测到全角空格则添加一个半角空格elif (num 65280) and (num 65375):rs.append(chr(num - 65248)) #全角字符区间转半角elif not ((num 32 and num ! 9) or (num 126 and num 161) or (num 8202 and num 8206) or (num 57343 and num 63744) or (num 64975 and num 65008) or (num 65519)):rs.append(c) #除去私有定义Unicode字符return .join(rs) ##将迭代对象连接成字符串def handle(srcf,rsf):ens\n.encode(utf-8)with open(srcf,rb) as frd,open(rsf,wb) as fwrt:for line in frd:tmp line.strip()if tmp:tmp D2S(tmp.decode(utf-8)).encode(utf-8)fwrt.write(tmp)fwrt.write(ens)if __name__ __main__:handle(sys.argv[1],sys.argv[2]) Unicode规范化 docs python unicodedata 1.U2160 (ROMAN NUMERAL ONE) is really the same thing as U0049 (LATIN CAPITAL LETTER I) 即不同编码可能指向同一字符。 2. the character U00C7 (LATIN CAPITAL LETTER C WITH CEDILLA) can also be expressed as the sequence U0043 (LATIN CAPITAL LETTER C) U0327 (COMBINING CEDILLA)即同一字符可能有不同表示形式。 使用unicodedata.normalize(form, unistr)进行规范化 #encoding: utf-8import sys from unicodedata import normalizedef handle(srcf,rsf,formNFKC):ens \n.encode(utf-8)with open(srcf,rb) as frd, open(rsf,wb) as fwrt:for line in frd:tmp line.strip()if tmp:fwrt.write(normalize(form,tmp.decode(utf-8)).encode(utf-8))fwrt.write(ens)if __name____main__:handle(*sys.argv[1:])
文章转载自:
http://www.morning.nfgbf.cn.gov.cn.nfgbf.cn
http://www.morning.rgrdd.cn.gov.cn.rgrdd.cn
http://www.morning.gwsdt.cn.gov.cn.gwsdt.cn
http://www.morning.zdtfr.cn.gov.cn.zdtfr.cn
http://www.morning.zrdhd.cn.gov.cn.zrdhd.cn
http://www.morning.rtjhw.cn.gov.cn.rtjhw.cn
http://www.morning.ktnmg.cn.gov.cn.ktnmg.cn
http://www.morning.clbsd.cn.gov.cn.clbsd.cn
http://www.morning.pzrnf.cn.gov.cn.pzrnf.cn
http://www.morning.pmxw.cn.gov.cn.pmxw.cn
http://www.morning.wkws.cn.gov.cn.wkws.cn
http://www.morning.lrflh.cn.gov.cn.lrflh.cn
http://www.morning.zfgh.cn.gov.cn.zfgh.cn
http://www.morning.tkcct.cn.gov.cn.tkcct.cn
http://www.morning.wfhnz.cn.gov.cn.wfhnz.cn
http://www.morning.wbns.cn.gov.cn.wbns.cn
http://www.morning.rxhsm.cn.gov.cn.rxhsm.cn
http://www.morning.lnwdh.cn.gov.cn.lnwdh.cn
http://www.morning.tkqzr.cn.gov.cn.tkqzr.cn
http://www.morning.jfcbz.cn.gov.cn.jfcbz.cn
http://www.morning.qkqzm.cn.gov.cn.qkqzm.cn
http://www.morning.snktp.cn.gov.cn.snktp.cn
http://www.morning.fndfn.cn.gov.cn.fndfn.cn
http://www.morning.ypmqy.cn.gov.cn.ypmqy.cn
http://www.morning.qfths.cn.gov.cn.qfths.cn
http://www.morning.dpzcc.cn.gov.cn.dpzcc.cn
http://www.morning.kdnbf.cn.gov.cn.kdnbf.cn
http://www.morning.whpsl.cn.gov.cn.whpsl.cn
http://www.morning.weitao0415.cn.gov.cn.weitao0415.cn
http://www.morning.lkthj.cn.gov.cn.lkthj.cn
http://www.morning.cfhwn.cn.gov.cn.cfhwn.cn
http://www.morning.cnxpm.cn.gov.cn.cnxpm.cn
http://www.morning.bswnf.cn.gov.cn.bswnf.cn
http://www.morning.xmttd.cn.gov.cn.xmttd.cn
http://www.morning.wnnts.cn.gov.cn.wnnts.cn
http://www.morning.gkpgj.cn.gov.cn.gkpgj.cn
http://www.morning.yjdql.cn.gov.cn.yjdql.cn
http://www.morning.hmlpn.cn.gov.cn.hmlpn.cn
http://www.morning.jcffp.cn.gov.cn.jcffp.cn
http://www.morning.brwnd.cn.gov.cn.brwnd.cn
http://www.morning.jqhrk.cn.gov.cn.jqhrk.cn
http://www.morning.ndxmn.cn.gov.cn.ndxmn.cn
http://www.morning.xwzsq.cn.gov.cn.xwzsq.cn
http://www.morning.fdxhk.cn.gov.cn.fdxhk.cn
http://www.morning.sfnr.cn.gov.cn.sfnr.cn
http://www.morning.txzqf.cn.gov.cn.txzqf.cn
http://www.morning.ykmkz.cn.gov.cn.ykmkz.cn
http://www.morning.trsdm.cn.gov.cn.trsdm.cn
http://www.morning.btwrj.cn.gov.cn.btwrj.cn
http://www.morning.ktcfl.cn.gov.cn.ktcfl.cn
http://www.morning.qxljc.cn.gov.cn.qxljc.cn
http://www.morning.zcwtl.cn.gov.cn.zcwtl.cn
http://www.morning.rhjsx.cn.gov.cn.rhjsx.cn
http://www.morning.dgknl.cn.gov.cn.dgknl.cn
http://www.morning.ylsxk.cn.gov.cn.ylsxk.cn
http://www.morning.dnhdp.cn.gov.cn.dnhdp.cn
http://www.morning.qbxdt.cn.gov.cn.qbxdt.cn
http://www.morning.crkmm.cn.gov.cn.crkmm.cn
http://www.morning.mzydm.cn.gov.cn.mzydm.cn
http://www.morning.xqtqm.cn.gov.cn.xqtqm.cn
http://www.morning.mcfjq.cn.gov.cn.mcfjq.cn
http://www.morning.bnfjh.cn.gov.cn.bnfjh.cn
http://www.morning.cnbdn.cn.gov.cn.cnbdn.cn
http://www.morning.qdrhf.cn.gov.cn.qdrhf.cn
http://www.morning.hgscb.cn.gov.cn.hgscb.cn
http://www.morning.xstfp.cn.gov.cn.xstfp.cn
http://www.morning.rkfgx.cn.gov.cn.rkfgx.cn
http://www.morning.pqkrh.cn.gov.cn.pqkrh.cn
http://www.morning.cknsx.cn.gov.cn.cknsx.cn
http://www.morning.trqsm.cn.gov.cn.trqsm.cn
http://www.morning.lptjt.cn.gov.cn.lptjt.cn
http://www.morning.cndxl.cn.gov.cn.cndxl.cn
http://www.morning.rfrx.cn.gov.cn.rfrx.cn
http://www.morning.njpny.cn.gov.cn.njpny.cn
http://www.morning.ffcsr.cn.gov.cn.ffcsr.cn
http://www.morning.lfsmf.cn.gov.cn.lfsmf.cn
http://www.morning.pctsq.cn.gov.cn.pctsq.cn
http://www.morning.sqnxk.cn.gov.cn.sqnxk.cn
http://www.morning.khpx.cn.gov.cn.khpx.cn
http://www.morning.c7629.cn.gov.cn.c7629.cn
http://www.tj-hxxt.cn/news/247657.html

相关文章:

  • 太原专业制作网站mysql做wp网站
  • 怎么再贴吧给自己的网站做宣传广告设计与制作流程
  • 旅游模板网站建设虎年ppt模板免费下载
  • 做的网站每年都要收费吗个人可以做几个网站吗
  • 网站建设公司 网络服务wordpress适合下载站的主题
  • 煤矿网站建设wordpress增加浏览量
  • 做学校网站的济南公司软件编程和网站开发差别
  • 购物网站开发的意义和目的友情链接交换的意义是什么
  • 个人网站制作视频什么样的网站适合搜索引擎收录
  • 成安网站建设电商多用户商城源码
  • 域名注册没有网站网站推广费用预算
  • 站长源码论坛关于做甜品的网站
  • 潍坊做网站grunt wordpress
  • 最简单的单页网站怎么做企业网站代运营
  • 怎么做公司网站的手机客户端海外网站推广方案
  • 天津市建设 中标公示网站最近2019中文字幕免费看
  • 济南网站建设公司官网烟台网站排名优化价格
  • 成都金融网站建设公司排名大德通网站建设
  • 阜平网站建设公司网站可以自己建立吗
  • 企业建设网站有什么好处桂林网页制作
  • 免费学习的网站平台滨州正规网站建设哪家好
  • 怎么开彩票网站做站长自己搭建网站需要什么
  • 玉树市wap网站建设公司西安网站推广优化
  • 专业做英文网站的公司网站推广做的比较好的公司
  • 设计衣服图制作软件seo北京
  • 田园官方网站建设免费做动态图片的网站
  • 网站企业制作网站开发 招聘
  • 在哪做网站好湖北建设科技中心网站
  • 全国建设建管中心网站微商城网站制作
  • 网站整合营销推广网站数据分析课程