首页| 论坛| 消息
主题:xpath抓取的值有空格换行符等问题
回帖:import scrapy
class QuoteSpider(scrapy.Spider):
name = 'quote'
start_urls = [
'http://quotes.toscrape.com/tag/humor/',
]
def parse(self, response):
for quote in response.css('div.quote'):
yield {
'text': quote.css('span.text::text').get(),
'author': quote.xpath('span/small/text()').get(),
}
next_page = response.css('li.next a::attr("href")').get()
if next_page is not None:
yield response.follow(next_page, self.parse)
下一楼›:# -*- coding: utf-8 -*-
# Define here the models for your scraped items
#
# Se ..
‹上一楼:#每爬完一个网页会回调parse方法
def parse(self, response):
hx=response.xpath('/ ..

查看全部回帖(10)
«返回主帖