scrapy xpath / css

 

title = response.xpath('//h2[@class="margin-top-0"]/a/text()')
read_num = response.xpath('//div[@class="col-md-12"]/p[@class="text-muted"]/small/text()').extract()[3].strip().replace('阅读(', '').replace(')', '')
commen_num = response.xpath('//div[@class="col-md-12"]/p[@class="text-muted"]/small/text()').extract()[4].strip().replace('评论(', '').replace(')', '')
add_time = response.xpath('//div[@class="col-md-12"]/p[@class="text-muted"]/small/text()').extract()[5].strip()
content = response.xpath('//div[@class="content"]//*').extract()[0]
tag_list = response.xpath('//a[@class="text-muted"]/text()').extract()
tag_str = '$$'.join(tag_list)

title = response.css(".margin-top-0 a::text").get()
read_num = response.css("p.text-muted small::text").getall()[3].strip().replace('阅读(', '').replace(')', '')
commen_num = response.css("p.text-muted small::text").getall()[4].strip().replace('评论(', '').replace(')', '')
add_time = response.css("p.text-muted small::text").getall()[5].strip()
content = response.css(".content *").getall()
tag_list = response.css("a.text-muted::text").getall()
tag_str = '$$'.join(tag_list)

 

posted @ 2019-07-31 20:42  大智如蠢  阅读(223)  评论(0编辑  收藏  举报