安装python
# 前言
- 了解Python:学习Python的基础语法,掌握Python的基本操作,例如变量、列表、循环和条件语句等。
- 学习HTTP协议:理解HTTP协议,学习HTTP请求和响应的基本知识。
- 学习正则表达式:正则表达式是爬虫中非常重要的工具,可以帮助你快速地从网页中提取所需的数据。
- 学习网络爬虫库:Python中有许多优秀的网络爬虫库,例如BeautifulSoup、Scrapy和Requests等。学习这些库的使用方法和基本原理。
- 实战练习:选择一些简单的网站进行练习,例如爬取豆瓣电影的排行榜,或者爬取新闻网站的头条新闻等。
- 学习反爬虫技术:在爬虫过程中,网站有可能会设置反爬虫机制。因此,学习反爬虫技术,了解如何绕过网站的反爬虫机制也是非常重要的。
爬虫三部曲
- 抓取页面
- 分析页面
- 存储数据
# 使用阿里云镜像安装python
开始前,Linux镜像要更换成阿里云镜像,步骤参考此处 (opens new window)
sudo yum install -y gcc openssl-devel bzip2-devel libffi-devel
sudo tee /etc/yum.repos.d/aliyun-python310.repo <<-'EOF'
[aliyun-python310]
name=Aliyun Python 3.10
baseurl=https://mirrors.aliyun.com/centos/7.6.1810/python310/x86_64/
enabled=1
gpgcheck=0
EOF
sudo yum install -y python310
sudo yum install -y python310 --installroot=/usr/local/python3.10
python3.10 --version
./configure --prefix=/usr/local/python3.10.10 --enable-shared
make
make install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 安装包
- pip
- wheel 网络较差时,下载结尾是.whl的安装包
# 必要安装
- pip3 install requests 用于请求
- pip3 install selenium 用于自动化测试
# 浏览器驱动
chromeDriver https://chromedriver.chromium.org/ chromedriver.storage.googleapis.com
geckoDriver firefox浏览器驱动
编辑 (opens new window)