国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

python - Scrapy中xpath用到中文報(bào)錯(cuò)

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

問(wèn)題描述

問(wèn)題描述

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

報(bào)錯(cuò):ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

問(wèn)題解答

回答1:

參見(jiàn)文章:解決Scrapy中xpath用到中文報(bào)錯(cuò)問(wèn)題

解決方法

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

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

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

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

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

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

整個(gè)字符串前加個(gè)u試試

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 元阳县| 池州市| 米泉市| 教育| 彭山县| 高邑县| 宕昌县| 新乡县| 武清区| 金寨县| 盐边县| 琼中| 鄂托克旗| 泰安市| 东港市| 古交市| 玉田县| 丹棱县| 平定县| 广州市| 尤溪县| 新和县| 沁阳市| 罗山县| 鹤峰县| 廉江市| 托克托县| 长武县| 刚察县| 抚州市| 龙川县| 阳新县| 贵南县| 革吉县| 永兴县| 涿州市| 景德镇市| 井陉县| 左云县| 庆云县| 伽师县|