python css选择器学习

# -*- coding: utf-8 -*-
import scrapy
import re


class JobboleSpider(scrapy.Spider):
    name = 'jobbole'
    allowed_domains = ['blog.jobbole.com']
    start_urls = ['http://blog.jobbole.com/110287/']

    def parse(self, response):
        #使用CSS选择器
        title = response.css(".entry-header h1::text").extract_first("")
        create_date = response.css(".entry-meta-hide-on-mobile::text").extract_first("").strip().replace("·","").strip()
        praise_nums = response.css("span.vote-post-up h10::text").extract_first("")
        fav_nums = response.css("span.bookmark-btn ::text").extract_first("")
        match_re = re.match(".*?(\d+).*", fav_nums)
        if(match_re):
            fav_nums = match_re.group(1)
        comment_nums = response.css("a[href='#article-comment'] span::text").extract()[0]
        match_re = re.match(".*?(\d+).*",comment_nums)
        if(match_re):
            comment_nums = match_re.group(1)
        content = response.css("div.entry").extract()[0]
        tag = response.css("p-entry-meta-hide-on-mobile a::text").extract()[0]
        pass

你可能感兴趣的:(python)