码迷,mamicode.com
首页 > 编程语言 > 详细

python print 方法 打印 unicode 遇到的坑

时间:2018-09-25 18:29:08      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:max   text   方法   container   int   ext   link   bsp   contain   

今天使用bs4 写爬虫(爬取baidu搜索url),遇到Unicode编码无法转正常字体,经过反复排查,发现python2.x版本中的print方法打印书写格式问题:

def get_maximum_pages(soup_content,link_re):
    div=soup_content.find(div,id=wrapper).find(div,id=wrapper_wrapper).find(div,id=container).find(div,id=page)
    a_list = div.find_all(a)
    next_page = a_list[len(a_list)-1]
    next_text = next_page.get_text()print("next_text:",next_page_text)   //此处无论怎么调试,都一直显示(‘next_text:‘, u‘\u4e0b\u4e00\u9875>‘)

 

1、python2.x 中正确写法:   

      print "next_text:",next_page_text 

     或者

     print("next_text:"+next_page_text )

    错误格式:print("next_text:",next_page_text)

python print 方法 打印 unicode 遇到的坑

标签:max   text   方法   container   int   ext   link   bsp   contain   

原文地址:https://www.cnblogs.com/songfucai/p/9701068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!