Python-argparse
参考文献
https://docs.python.org/3/library/argparse.html
argparse
简单用法
12345678910# 创建解析器parser = argparse.ArgumentParser( prog='ProgramName', description='What the program does', epilog='Text at the bottom of help')# 添加参数parser.add_argument('filename') # positional argumentparser.add_argument('-c', '--count') # option that takes a valueparser.add_argument('-v ...
Python-Selenium
参考文献
Selenium
基本用法
初始化浏览器对象
访问页面
查找节点
查找单个节点
查找多个节点
节点交互
动作链
获取节点信息
获取属性
获取文本值
获取ID,位置,标签名和大小
切换Frame
延时等待
隐式等待
显示等待
前进和后退
选项卡管理
异常处理
反屏蔽
无头模式
Python-XPath
参考文献
Python3网络爬虫开发实战第二版
XPath 菜鸟教程
XPath
术语
在 XPath 中,有七种类型的节点:元素、属性、文本、命名空间、处理指令、注释以及文档(根)节点.XML 文档是被作为节点树来对待的.树的根被称为文档节点或者根节点.
轴(Axes)
轴可定义相对于当前节点的节点集.
轴名称
结果
ancestor
选取当前节点的所有先辈(父、祖父等)
ancestor-or-self
选取当前节点的所有先辈(父、祖父等)以及当前节点本身.
attribute
选取当前节点的所有属性.
child
选取当前节点的所有子元素.
descendant
选取当前节点的所有后代元素(子、孙等)
descendant-or-self
选取当前节点的所有后代元素(子、孙等)以及当前节点本身.
following
选取文档中当前节点的结束标签之后的所有节点.
following-sibling
选取当前节点之后的所有兄弟节点
namespace
选取当前节点的所有命名空间节点.
parent
选取当前节点的父节点.
...
Python-爬虫
参考文献
爬虫
爬虫实际上是用浏览器访问的方式模拟了访问网站的过程,整个过程包括三个阶段:打开网页、提取数据和保存数据
在 Python 中,这三个阶段都有对应的工具可以使用。
在“打开网页”这一步骤中,可以使用 Requests 访问页面,得到服务器返回给我们的数据,这里包括 HTML 页面以及 JSON 数据。
在“提取数据”这一步骤中,主要用到了两个工具。针对 HTML 页面,可以使用 XPath 进行元素定位,提取数据;针对 JSON 数据,可以使用 JSON 进行解析。
在最后一步“保存数据”中,我们可以使用 Pandas 保存数据,最后导出 CSV 文件。
Requests访问页面
Requests 是 Python HTTP 的客户端库,编写爬虫的时候都会用到,编写起来也很简单。它有两种访问方式:Get 和 Post。这两者最直观的区别就是:Get 把参数包含在 url 中,而 Post 通过 request body 来传递参数.
123r = requests.get('http://www.douban.com') ...
Python-pandas
参考文献
像Excel一样使用python进行数据分析
pandas
Series
Series 是个定长的字典序列.说是定长是因为在存储的时候,相当于两个 ndarray,这也是和字典结构最大的不同.因为在字典的结构里,元素的个数是不固定的.
Series有两个基本属性:index 和 values.在 Series 结构中,index 默认是 0,1,2,……递增的整数序列,当然也可以自己来指定索引,比如 index=[‘a’, ‘b’, ‘c’, ‘d’].
123456789101112import pandas as pdfrom pandas import Series, DataFramex1 = Series([1, 2, 3, 4])x2 = Series(data=[1, 2, 3, 4], index=['a', 'b', 'c', 'd'])print(x1)print(x2)# 采用字典形式创建Seriesd = {'a': 1, ' ...
Python-数据分析
参考文献
极客时间 数据分析实战45讲 陈旸
数据分析
数据分析分成三个重要的组成部分
数据采集
数据挖掘
数据可视化
数据挖掘
数据挖掘的过程
商业理解: 数据挖掘不是我们的目的,我们的目的是更好地帮助业务,所以第一步我们要从商业的角度理解项目需求,在这个基础上,再对数据挖掘的目标进行定义.
数据理解: 尝试收集部分数据,然后对数据进行探索,包括数据描述、数据质量验证等.这有助于你对收集的数据有个初步的认知.
数据准备: 开始收集数据,并对数据进行清洗、数据集成等操作,完成数据挖掘前的准备工作.
模型建立: 选择和应用各种数据挖掘模型,并进行优化,以便得到更好的分类结果.
模型评估: 对模型进行评价,并检查构建模型的每个步骤,确认模型是否实现了预定的商业目标.
上线发布: 模型的作用是从数据中找到金矿,也就是我们所说的“知识”,获得的知识需要转化成用户可以使用的方式,呈现的形式可以是一份报告,也可以是实现一个比较复杂的、可重复的数据挖掘过程.数据挖掘结果如果是日常运营的一部分,那么后续的监控和维护就会变得重要.
数据挖掘的十大算法
分类算法: C4.5,朴素贝叶斯 ...
Python-numpy
参考文献
numpy
在 NumPy里有两个重要的对象:
ndarray(N-dimensional array object)解决了多维数组问题
ufunc(universal function object)则是解决对数组进行处理的函数
NumPy的数组类被调用ndarray.它也被别名所知 array.请注意,numpy.array这与标准Python库类不同array.array,后者只处理一维数组并提供较少的功能.ndarray对象更重要的属性是:
ndarray.ndim - 数组的轴(维度)的个数.在Python世界中,维度的数量被称为rank.
ndarray.shape - 数组的维度.这是一个整数的元组,表示每个维度中数组的大小.对于有n行和m列的矩阵,shape 将是 (n,m).因此,shape 元组的长度就是rank或维度的个数 ndim.
ndarray.size - 数组元素的总数.这等于 shape 的元素的乘积.
ndarray.dtype - 一个描述数组中元素类型的对象.可以使用标准的Python类型创建或指定dtype.另外NumPy提 ...
Python-requests
参考文献
requests
示例
get
123456789101112import requestsrep = requests.get("http://www.baidu.com")# 带参数params = { 'wd':'cs'}rep = requests.get("http://www.baidu.com",params=params)