学习python-day017---转自Python分布式爬虫打造搜索引擎Scrapy精讲

第三百四十节,Python分布式爬虫打造搜索引擎Scrapy精讲—css选择器

css选择器

1、

在这里插入图片描述
2、
在这里插入图片描述
3、
在这里插入图片描述

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

::text获取标签文本

举例:

extract_first(’’)获取过滤后的数据,返回字符串,有一个默认参数,也就是如果没有数据默认是什么,一般我们设置为空字符串

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

-- 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)

复制代码

转载目的:形成完整的学习笔记,备查回溯

发布了41 篇原创文章 · 获赞 0 · 访问量 356

猜你喜欢

转载自blog.csdn.net/u013683613/article/details/104359380