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

相關文章
相關標籤/搜索