scrapy爬虫程序xpath中文编码报错
2017-03-23
问题描述:
#选择出节点中“时间”二字
<h2>时间</h2>
item["file_urls"]= response.xpath("//h2[text()= '时间']")
#报错:ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters
解决方法:
(1)s = u'时间'
item["time"]= response.xpath("//h2[text()= '%s']"%(s))
(2)item["time"]= response.xpath(u"//h2[text()= '时间']")