# -*- coding: utf-8 -*-
import scrapy
import re
class JobboleSpider(scrapy.Spider):
name = "jobbole"
allowed_domains = ["blog.jobbole.com"]
start_urls = ['http://blog.jobbole.com/113560/']
def parse(self, response):
# re_selector = response.xpath("/html/body/div[1]/div[3]/div[1]/div[1]/h1")
# re2_selector = response.xpath('//*[@id ="post-113560"]/div[1]/h1/text()')
# 下面create_date表示日期,praise_nums点赞数 fav_num收藏数 comment_nums评论数cotent正文
# tag_list是日期后面的内容 tags连接的字符串
title = response.xpath('//*[@id ="post-113560"]/div[1]/h1/text()').extract()[0]
create_date = response.xpath('//*[@id="post-113560"]/div[2]/p/text()').extract()[0].strip().replace("·", "").strip()
praise_nums = int(response.xpath('//*[@id="post-113560"]/div[3]/div[3]/span[1]/h10/text()').extract()[0])
fav_nums= response.xpath('//*[@id="post-113560"]/div[3]/div[3]/span[2]/text()').extract()[0]
match_re=re.match(".*(\d+).*",fav_nums)
if match_re:
fav_nums=match_re.group(1)
comment_nums=response.xpath('//*[@id="post-113560"]/div[3]/div[3]/a/span/text()').extract()[0]
match_re = re.match(".*(\d+).*", comment_nums)
if match_re:
comment_nums=match_re.group(1)
cotent= response.xpath('//*[@id="post-113560"]/div[3]').extract()[0]
tag_list=response.xpath("//p[@class='entry-meta-hide-on-mobile']/a/text()").extract()
tag_list=[element for element in tag_list if not element.strip().endswith("评论")]
tags =",".join(tag_list)
pass
内容提取的源码
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...