python爬虫

Python:
1.概述:
1.语言
2.开发起来简洁 =》 java
2.使用场景:
1.数据分析 =》 numpy 、pandas
2.web 开发 =》 用的不多 、 百度
3.游戏开发 =》 用的不多
4.AI (机器学习、深度学习)
5.爬虫

1.部署安装:

1.安装: 
	1.python 原生的安装包  www.python.org
	2.anaconda 安装 =》 
		1.python 有的
		2.有一些丰富的第三方库

	anaconda:
		1.下载安装包
		2.安装 =》 next 

2.开发python :
1.ide :
1.pycharm =》 idea
2.jupyter =》web 版的开发

3.python 语法
1.基本数据结构
1.数值型
int 整型
float 小数

	2.字符串	
		str

1.注释
	1.单行注释 # 
	2.多行注释 :
		''' 
			xxxx
		'''

		"""
		xxxx 
		"""

2.数值类型
	1.int 

n1 = 10
print(n1)
print(type(n1))
2.float
n2 = 10.1
print(n2)
print(type(n2))

3.str:
	1.单引号 或者双引号 【普通字符串的定义】
	'a' "abc"
	2.多行字符串【跟多行注释有点类似】
	"""
		asdas
	"""

s1 = ‘longshao’
s2 = “qiaoshao”
print(s1)
print(s2)
print(type(s1))
print(type(s2))
s3 = ‘’’
xinwei 说咱班美女多,我说 真的多
‘’’
print(s3)
print(type(s3))

4.运算符
算数运算符:+、-、*、/、%、**、//:
n1 = 5
n2 = 10
n3 = 2
print(n1 + n2)
print(n1 - n2 )
print(n1 * n2 )
print(n1 / n2 )
print(n1 % n2 )
print(n1 ** n3 )
print(n1 // n3 )
比较运算符: == < > != <= >=
1.python 中:
bool
n1 = 10
n2 = 20
print(n1 == n2 )
print(n1 <= n2 )
print(n1 >= n2 )
print(n1 != n2 )
print(n1 > n2 )
print(n1 < n2)
print(type(n1 == n2))
赋值运算符:= += -= /= %= //= **=
n1 = 10
n2 = 20
print(n1)
print(n2)
print(“n1=”,n1,‘n2=’,n2)
n2 +=n1
print(“n1=”,n1,‘n2=’,n2)
n2 -=n1
print(“n1=”,n1,‘n2=’,n2)
n2 /=n1
print(“n1=”,n1,‘n2=’,n2)
n2 *=n1
print(“n1=”,n1,‘n2=’,n2)
n2 **=n1
print(“n1=”,n1,‘n2=’,n2)
n2 //=n1
print(“n1=”,n1,‘n2=’,n2)
n2 %= n1
print(“n1=”,n1,‘n2=’,n2)
逻辑运算符:and or not
n1 = True
n2 = False
print(n1 and n2)
print(n1 or n2 )
print(not n1 )
成员运算符:in 、not in
s1 = “ningshao”
print(‘n’ in s1)
print(‘x’ not in s1)
爬虫:
1.百度百科
2.自己理解:
通过代码、模拟浏览器上网 然后抓取数据的过程

2.爬虫是否合法?
1.法律允许
2.有法律风险的

3.统一规定? 【法律界限】
robots.txt协议

4.爬虫的分类:
1.获取一整张页面 【通用爬虫】
2.获取一整张页面 部分数据 【聚焦爬虫】
3.检查页面更新、获取页面最新的更新的数据 【增量式爬虫】

5.爬虫的规则:
1.反爬策略:
门户网站 通过 技术手段 防止爬虫程序对页面爬取数据
2.反 反爬策略
爬虫程序 通过 技术手段 对页面爬取数据

http 与https
service 与 client 进行数据交互的一种形式
request:
User-Agent: 请求载体的身份标识
response:
Content-Type:服务器响应client的数据类型

爬虫的框架:
scrap :

An open source and collaborative framework for extracting the data you need from websites.
In a fast, simple, yet extensible way.
1.开源的爬虫框架
2.快速、简单、高效的方式

2.安装部署

3.基本使用
1.创建一个项目
scrapy startproject test_scrapy

	1.项目目录:
		1.scrapy.cfg  【项目的配置文件】
		2.settings.py  【项目的配置文件】
		3. spiders/  【防止 爬虫代码的目录】
2.编写爬虫代码
	1.创建一个 爬虫代码
	scrapy genspider [options] <name> <domain>

	scrapy genspider python01 www.xxx.com

 '''
name:
    1.不能重复
    2.爬虫文件的名字
'''
name = 'python01'
'''
   scrapy 允许爬取的 url 
'''
allowed_domains = ['www.baidu.com']
'''
    scrapy 去爬取的 url 列表
'''
start_urls = ['http://www.baidu.com/','https://www.sougou.com']

3.启动爬虫项目
	1.启动命令
	scrapy runspider [options] <spider_file>

	scrapy runspider ./test_scrapy/spiders/python01.py
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值