问题描述
links = sel.xpath('//i[contains(@title,"置顶")]/following-sibling::a/@href').extract()
报错:ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters
links = sel.xpath('//i[contains(@title,"置顶")]/following-sibling::a/@href').extract()
报错:ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters
4 回答4.4k 阅读✓ 已解决
4 回答3.8k 阅读✓ 已解决
1 回答3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
1 回答4.5k 阅读✓ 已解决
1 回答3.8k 阅读✓ 已解决
1 回答2.8k 阅读✓ 已解决
参见文章:解决Scrapy中xpath用到中文报错问题
解决方法
方法一:将整个xpath语句转成Unicode
方法二:xpath语句用已转成Unicode的title变量
方法三:直接用xpath中变量语法(
$
符号加变量名)$title
, 传参title即可