久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

python - Scrapy中xpath用到中文報錯

瀏覽:149日期:2022-06-27 08:01:12

問題描述

問題描述

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

問題解答

回答1:

參見文章:解決Scrapy中xpath用到中文報錯問題

解決方法

方法一:將整個xpath語句轉(zhuǎn)成Unicode

links = sel.xpath(u’//i[contains(@title,'置頂')]/following-sibling::a/@href’).extract()

方法二:xpath語句用已轉(zhuǎn)成Unicode的title變量

title = u'置頂'links = sel.xpath(’//i[contains(@title,'%s')]/following-sibling::a/@href’ %(title)).extract()

方法三:直接用xpath中變量語法($符號加變量名)$title, 傳參title即可

links = sel.xpath(’//i[contains(@title,$title)]/following-sibling::a/@href’,).extract()回答2:

整個字符串前加個u試試

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 清镇市| 常德市| 彰武县| 雅安市| 大冶市| 汉源县| 苏州市| 闵行区| 腾冲县| 瑞昌市| 定襄县| 保靖县| 康平县| 布尔津县| 吉木乃县| 白水县| 灌南县| 烟台市| 芒康县| 车险| 福鼎市| 云浮市| 平凉市| 隆化县| 阿尔山市| 东阿县| 长沙市| 安仁县| 太康县| 陆河县| 常德市| 弋阳县| 依兰县| 铁岭县| 唐海县| 云龙县| 阿克陶县| 青神县| 新巴尔虎左旗| 马公市| 孟津县|