“化鲲为鹏,我有话说”如何用鲲鹏弹性云服务器部署《Python网络爬虫开发环境》

举报
yxmos2019 发表于 2019/11/14 13:34:19 2019/11/14
【摘要】 python的网络爬虫功能是有目共睹的,我这边简单介绍下我所理解的,在鲲鹏服务器上布署网络爬虫实战开发环境的一个过程!首先:需ECS有python环境基础(这论坛里也有很多人发过相关的贴子,太家可以选择性的查看下),再安装相关的依赖包!-------------------------------------------------------------------------------...

python的网络爬虫功能是有目共睹的,我这边简单介绍下我所理解的,在鲲鹏服务器上布署网络爬虫实战开发环境的一个过程!

首先:需ECS有python环境基础(这论坛里有很多人发过相关的贴子,太家可以选择性的查看下),后面再一步步怎样安装依赖包!

环境好了后面的一些开发实战详解,完整案例演示,源码框架剖析等!

-----------------------------------------------------------------------------------------------------------------------------------

因所有的操作都是现学现卖,所以有兴趣可以等贴子完结后再仔细查看,本人先起个草稿先!请看官多担待些!

1、ECS操作系统和位数信息

规格 : 2vCPUs | 4GB | kc1.large.2

镜像 :Ubuntu 18.04 64bit with ARM

image.png

又省了一步,系统都自带了!Python 2和Python 3镜像都包含有呀!!!~~~~~~~~~~~~~~~~

image.png

2、安装依赖包、实战源码维护地址:https://github.com/zhangziliang04/requests-html/tree/master/example/Exam3.8

安装依赖包前最好升级下pip,刚实际操作的时候碰到一大堆报错,仔细研究了下,发现不能这样操作,得先解决版本切换问题


sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
update-alternatives --list python

root身份,使用以下命令随时在列出的python替换版本中任意切换

sudo su
update-alternatives --config python

输入“1”,就切换到2.7版本了,相反如果之前默认版本为2.7的输入“2”则切换到3.6版本了。

python --version

看到是你想要的版本了!~!


解决完python切换问题,再重装下pip,装源的过程中,又碰到源下载不OK问题,又得更换源!汗,麻烦事真多呀

到源目录下,清空,然后再把国内源添加进去

cd /etc/apt
ll
>sources.list
vim sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
apt-get update
apt install python3-pip
pip install -U pip   #针对2.7版本
pip3 install -U pip  #针对3.6版本
pip3 install requests-html

image.png


requests-html 全新爬虫包来袭

全面支持解析JavaScript!
CSS 选择器 (jQuery风格,).
XPath 选择器, for the faint at heart.
自定义user-agent (就像一个真正的web浏览器).
自动追踪重定向.
连接池与cookie持久化.
令人欣喜的请求体验,魔法般的解析页面.

image.png



【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

举报
请填写举报理由
0/200