Python进阶训练营(一)(视频代码齐) 网盘download:Python进阶训练营 提娶马:uuiy 课程介绍、学习方法与简单爬虫 01 课程介绍 02 绪论 03 提升Python 开发效率的工具 04 复习Python 的基础语法 05 使用Python 库获取豆瓣影评和书评
学习目标 掌握高效系统学习Python 的方法 提升Python 开发效率的工具 复习基础Python 语法
01 课程介绍
- 完整案例:NLP 舆情系统 需求描述-数据收集-数据处理-语料处理-深度学习-结果测评-调参-展示
- Python 底层功能 作用域问题 面向对象编程 多线程、协程 爬虫框架、Web 框架 课程介绍
02 绪论 为什什么学习Python
- Python 语言足够流行
- Python 语言足够“简单”
- 生态完善
Python 作为第⼆二语⾔言
- 作为第⼆二语⾔言可以做知识迁移
- 前端开发可以从爬⾍虫项⽬目开始⽆无痛⼊入⼿手
- 后端开发可以对⽐比静态语⾔言和动态语⾔言的差异
高效学习Python 的方法
- 建⽴立⾼高效的学习模型
- 了了解Python 的⻓长处
- 了了解Python 的特性
- 多看⾼高⼿手的代码(GitHub)
- 好的问题是成功的⼀一半(Google、Stack Overflow)
- ⻛风格指引(PEP8、Google Python Style Guides) 03 提升Python 开发效率的工具
提升Python 开发效率的工具
- Visual Studio Code:高效的IDE
- pylint
- autopep8
- remote- ssh
- Python3.6 or Python3.7:不同的版本差别在哪里?
- Jupyter Notebook:数据科学家的最爱
从一个需求开始 获取豆瓣读书Top 250 的书籍名字和评分
实现步骤:
- F12 调试模式分析网页源代码
- 用Requests 爬取网页全部内容
- 用Beautiful Soup 解析网页提取关键信息
- 用csv 文件存储书籍名字和评分
pip 安装加速 国内常见的镜像站: 豆瓣 清华 升级pip: 方法一: pip install - i pypi.tuna.tsinghua.edu.cn/simple pip -U 方法二: pip config set global.index- url pypi.doubanio.com/simple/pip install pip -U
pip 安装加速 配置文件: windows: c:\Users\xxx\pip\pip.ini Linux: ~/.pip/pip.conf 配置文件格式: [global] index- url = pypi.tuna.tsinghua.edu.cn/simple
翻页都是怎么做到的 search.bilibili.com/all?keyword… search.douban.com/book/subjec… weibo.com/a/aj/transf… weibo.com/a/aj/transf…
格式化字符串 三种常用的格式化字符串方式:
- % 操作符
- str.format(*args, **kwargs)
- f- string:Python 3.6 引入,该方法源于PEP498
格式化字符串 % 操作符- - printf 风格的字符串格式化 import math print('The value of Pi is approximately %5.3f.' % math.pi)
输出:The value of Pi is approximately 3.142.
.format - - 更加灵活 print('{1} and {0}'.format('spam', 'eggs’))
输出: eggs and spam
print('The story of {0}, {1}, and {other}.'.交流V(cmL46679910)format('Bill', 'Manfred', other='Georg'))
输出:The story of Bill, Manfred, and Georg.
参考: docs.python.org/zh- cn/3.6/library/string.html#formatstrings f- string:Python 3.6 引入,该方法源于PEP 498。 docs.python.org/zh-cn/3.6/w… f- string 和%操作符、.format 比较:
- 性能更好
- 易读性好 三种写法比较 firstname = 'yin' lastname = 'wilson' print('Hello, %s %s.' % (lastname, firstname)) print('Hello, {1} {0}.'.format(firstname, lastname)) print(f'Hello, {lastname} {firstname}.') f- string还可以做其他事情: f'{ 2 * 5 }' class Person: def init(self, first_name, last_name): self.first_name = first_name self.last_name = last_name def str(self): return f'hello, {self.first_name} {self.last_name}.' def repr(self): return f'hello, {self.first_name} {self.last_name}.' me = Person('yin', 'wilson') print(f'{me}')
04 复习Python 基础知识 赋值使用“=”符号 Python 3.8会引入海象运算符“:=” (PEP572) 赋值前不需要指定类型(分配内存) 数值、布尔、字符串、序列赋值前不需要指定类型(分配内存)
Python 的执行方法:
shell> python filename.py
Python 会将.py 文件编译成字节码pyc 格式文件,由Python 虚拟机执行
shell> python (回车)
python>交流V(cmL46679910) import whatyouwant
python> run python something
交互模式(解释模式)
总结:
- 通过静态页面爬虫复习了Python 的基础语法
- 了解Python 语言作为动态语言的特点
- 掌握静态页面数据收集的一般方法