python scrapy 中解决 xpath错误 ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL by

是因为 用css 或者xpath选择内容后 没有设置 只要内容 ,其中可能包含html等元素引起的

解决:

css 用 ::text"
xpath 用 //text()

末尾都加 .extract()

<div class="ace-line gutter-author-p-11895417 emptyGutter" data-author-initials="可" data-author-name="可可" data-author-link=""><a href="https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=s306eooi" target="_blank">限时抢占云服务 点击这里 <img src="https://img2018.cnblogs.com/blog/1484975/201907/1484975-20190704235050739-2056959333.png" alt=""></a></div>

猜你喜欢

转载自www.cnblogs.com/stillstep/p/11135625.html