国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

python - Scrapy中xpath用到中文報(bào)錯(cuò)
大家講道理
大家講道理 2017-06-30 09:55:44
0
2
1582

問(wèn)題描述

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

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

大家講道理
大家講道理

光陰似箭催人老,日月如移越少年。

全部回覆(2)
學(xué)習(xí)ing

請(qǐng)參考文章:解決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變數(shù)

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

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

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

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

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板