python print 方法 打印 unicode 遇到的坑

今天使用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)

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值