1九、 Python快速开发分布式搜索引擎Scrapy精讲—css选择器

百度云搜索,搜各类资料:http://www.lqkweb.com

搜网盘,搜各类资料:http://www.swpan.cn

css选择器css

一、web

image

二、dom

image

三、scrapy

image

 ::attr()获取元素属性,css选择器ide

::text获取标签文本post

举例:url

extract_first('')获取过滤后的数据,返回字符串,有一个默认参数,也就是若是没有数据默认是什么,通常咱们设置为空字符串spa

extract()获取过滤后的数据,返回字符串列表code

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

class PachSpider(scrapy.Spider):
    name = 'pach'
    allowed_domains = ['blog.jobbole.com']
    start_urls = ['http://blog.jobbole.com/all-posts/']

    def parse(self, response):

        asd = response.css('.archive-title::text').extract()  #这里也能够用extract_first('')获取返回字符串
        # print(asd)

        for i in asd:
            print(i)

image
【转载自:http://www.lqkweb.comblog

相关文章
相关标签/搜索