我是靠谱客的博主 可靠未来,这篇文章主要介绍python print 方法 打印 unicode 遇到的坑,现在分享给大家,希望可以做个参考。

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

复制代码
1
2
3
4
5
6
7
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'u4e0bu4e00u9875>')

 

1、python2.x 中正确写法:   

      print "next_text:",next_page_text 

     或者

     print("next_text:"+next_page_text )

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

转载于:https://www.cnblogs.com/husbandmen/p/9701068.html

最后

以上就是可靠未来最近收集整理的关于python print 方法 打印 unicode 遇到的坑的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(81)

评论列表共有 0 条评论

立即
投稿
返回
顶部