css选择器
1、
2、
3、
::attr()获取元素属性,css选择器
::text获取标签文本
举例:
extract_first(’’)获取过滤后的数据,返回字符串,有一个默认参数,也就是如果没有数据默认是什么,一般我们设置为空字符串
extract()获取过滤后的数据,返回字符串列表
在学习过程中有什么不懂得可以加我的
python学习资源qun,855 408 893
群里有不错的学习视频教程、开发工具与电子书籍。
与你分享python企业当下人才需求及怎么从零基础学习好python,和学习什么内容
# -*- 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)