如何替换文字" CDATA"?

时间:2015-01-13 06:56:40

标签: python python-2.7 web-scraping scrapy browser-cache

我试图从蜘蛛代码下面的cachdescription项中替换“CDATA”的文字:

item['CacheDescription']= response.xpath("//html").replace("CDATA" ,' ')

输出:

* <![CDATA[ */ function URLReplacePlus(strIn) { var a = "+"; var b = "%43"; var c = strIn; var i = c.indexOf(a); var l = b.length; while (i != -1) { c = c.substring(0,i) + b + c.substring(i + a.length,c.length);

1 个答案:

答案 0 :(得分:2)

您需要调用extract()来获取实际的字符串值:

response.xpath("//html").extract()[0].replace("CDATA" ,' ')