Scrapy无法提取文本

时间:2018-09-28 07:34:27

标签: web-scraping scrapy scrapy-spider

我正在学习沙哑,但是我陷入了困境 我使用的网站是https://wordpress.org/plugins/tags/category-image/

我正在提取网页上的某些文本 我使用休闲命令

fetch("https://wordpress.org/plugins/tags/category-image/")
response.xpath('//*[@class="plugin-author"]').extract_first()

输出:

'<span class="plugin-author">\n\t\t\t<i class="dashicons dashicons-admin-users"></i> Muhammad Said El Zahlan\t\t</span>'

我需要提取穆罕默德·赛义德·扎兰(

response.xpath('//*[@class="plugin-author"]/text()').extract_first()

输出:

'\n\t\t\t'

response.xpath('//*[@class="plugin-author"]/@span/text()').extract_first()

response.xpath('//*[@class="plugin-author"]/@span').extract_first()

response.xpath('//*[@class="plugin-author"]/@text()').extract_first()

给我一​​些线索

2 个答案:

答案 0 :(得分:0)

使用

response.xpath('//*[@class="plugin-author"]/text()')[1].extract()

输出:

' Muhammad Said El Zahlan\t\t'

答案 1 :(得分:0)

这是您的xml树:

<span class="plugin-author">
    <i class="dashicons dashicons-admin-users">
    </i> Muhammad Said El Zahlan\t\t
</span>

换句话说,您想要span/i/text()

response.xpath('//span[@class="plugin-author"]/i/text()').extract()

span//text :(范围内的任何文本)

response.xpath('//span[@class="plugin-author"]//text()').extract()