叽叽喳喳,嘻嘻哈哈

导航

[ 转 ] scrapy 中解决 xpath 中的中文编码问题

 

 

1、问题描述:

      实现定位<h2>品牌</h2>节点

      brand_tag = sel.xpath("//h2[text()= '品牌']")

      报错:ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters 

2、解决方法:

   (1)brand = u'品牌'
           brand_tag = sel.xpath("//h2[text()= '%s']"%(brand))

   (2)brand_tag = sel.xpath(u"//h2[text()= '品牌']")

 
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

http://blog.csdn.net/zcc_0015/article/details/52274996

 

posted on 2016-12-17 23:03  叽叽喳喳,嘻嘻哈哈  阅读(374)  评论(0编辑  收藏  举报