爬虫

Python:
tuple list set dict range str 分片 [::] 推导
函数:def 函数名称(参数):
实现函数体

参数种类:
必须参数
默认参数
关键参数
可变参数:tuple *参数名称 dict**kwargs

建议:默认参数一定要在必须参数之后定义,可变参数一定要定义在最后
函数种类:
外部函数
内部函数
匿名函数 lambda
装饰函数:@

函数 总是要返回的 如果没有return None总是被返回

面向对象:
对象:已存在可被使用的实例 万物皆对象 模块 、 函数、 变量、 类、 方法都是对象
class : 描述其他实例信息的对象
方法 : 定义其它实例行为的对象
方法与函数的区别:函数可独立定义和调用 方法不能独立定义,也不能独立调用
函数要依赖方法的实例才能调用
staticmethod
classmedhod

属性 : 定义其它实例特征的对象

stu = Student()
stu.jump = lambda x: print('你跳了{0}米'.format(x))
stu.jump(1.2)

import scrapy
class QuotesSpider(scrapy.Spider):
name = "kegongchang"
start_urls = [
'http://www.kgc.cn/',
]

def parse(self,response):
lis = response.css('h2.headline-title~ul>li>p>a::text').extract()
for txt in lis:
print(txt)

# def parse(self, response):
# herfs = response.css('h2.headline-title~ul>li>p>a::attr("href")').extract()
# for url in herfs:
# #解析出首页每个头条的文章链接并生成新的对象
# yield response.follow(url,self.ta)
#
# def ta(self,response):
# #解析页面中的标题和作者
# title = response.css('div.essay_top>h6::text').extract_first()
# author = response.css('div.essay_card.f1>span::text').extract_first()
# yield {
# 'title':title,
# 'author':author
# }

 

posted @ 2018-06-24 11:45  yuello  阅读(124)  评论(0)    收藏  举报