scrapy的汉字处理方法


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()= '品牌']")

1、问题描述:

unicode字符转换为中文

  
https://blog.csdn.net/xiaocy66/article/details/83479734


 

posted @ 2022-02-11 14:54  长白山  阅读(65)  评论(0)    收藏  举报