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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章