python3如何安装请求库

小编给大家分享一下python3如何安装请求库,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名申请、网页空间、营销软件、网站建设、长治网站维护、网站推广。

  • 环境说明

[root@localhost Python-3.6.6]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.4 (Maipo)
[root@localhost Python-3.6.6]# uname -a
Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Thu Jul 6 19:56:57 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost Python-3.6.6]# getenforce 
Disabled
[root@localhost Python-3.6.6]# systemctl status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@localhost Python-3.6.6]#
  • requests库 selenium库

pip3 install requests
pip3 install selenium
  • chromederiver安装

yum install Xvfb
yum install libXfont
yum install xorg-x11-fonts*
vim /etc/yum.repos.d/google.repo    
    [google]
    name=Google-x86_64
    baseurl=http://dl.google.com/linux/rpm/stable/x86_64
    enabled=1
    gpgcheck=0
    gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
yum install google-chrome-stable
yum install GConf2-3.2.6-8.el7.x86_64
wget http://chromedriver.storage.googleapis.com/70.0.3538.67/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedrive /usr/bin
chmod +x /usr/bin/chromedrive

chromedriver 
Starting ChromeDriver (v2.9.248304) on port 9515

#验证
python3
>>> from selenium import webdriver
>>> browser = webdriver.Chrome()
#会弹出一个空白的chrome

#默认情况下root用户不能调用chrome,建议为chrome建立一个单独用户
  • GeckoDriver安装

yum install firefox
wget https://github.com/mozilla/geckodriver/releases/download/v0.23.0/geckodriver-v0.23.0-linux64.tar.gz
tar xf geckodriver-v0.23.0-linux64.tar.gz -C /usr/bin
chmod +x geckodriver

#验证
python3
>>> from selenium import webdriver
>>> browser = webdriver.Firefox()
#会弹出一个空白的Firefox

以上,我们就可以利用chrome或者firefox进行网页抓取了,但是这样会有一个问题:因为程序的运行过程中需要一直开着浏览器。所以我们可以选用×××面的浏览器PhantomJS。

  • PhantomJS安装

wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar xf https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
cd phantomjs-2.1.1-linux-x86_64/bin
mv phantomjs /usr/bin/
chmod +x /usr/bin/phantomjs

#验证
python3
>>> from selenium import webdriver
>>> browser = webdriver.PhantomJS()
>>> browser.get('https://www.baidu.com')
>>> print (browser.current_url)
https://www.baidu.com/
>>>
#此时,不会打开浏览器,但是通过print打印了请求地址。说明可以正常使用。
  • aiohttp安装

aiohttp是一种类似requests的请求库,区别在于,aiohttp是一个提供异步web服务的库。

安装方式如下:

pip3 install aiohttp
pip3 install cchardet aioDNS #字符编码检测库及加速DNS解析的库

以上是“python3如何安装请求库”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!

分享文章:python3如何安装请求库
网站链接:https://www.cdcxhl.com/article0/jgsdio.html

成都网站建设公司_创新互联,为您提供网站设计公司网站排名品牌网站建设电子商务Google品牌网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

网站优化排名