千家信息网

python3如何安装请求库

发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,小编给大家分享一下python3如何安装请求库,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!环境说明[root@local
千家信息网最后更新 2025年02月02日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 -aLinux 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 requestspip3 install selenium
  • chromederiver安装

yum install Xvfbyum install libXfontyum 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.pubyum install google-chrome-stableyum install GConf2-3.2.6-8.el7.x86_64wget http://chromedriver.storage.googleapis.com/70.0.3538.67/chromedriver_linux64.zipunzip chromedriver_linux64.zipmv chromedrive /usr/binchmod +x /usr/bin/chromedrivechromedriver Starting ChromeDriver (v2.9.248304) on port 9515#验证python3>>> from selenium import webdriver>>> browser = webdriver.Chrome()#会弹出一个空白的chrome#默认情况下root用户不能调用chrome,建议为chrome建立一个单独用户
  • GeckoDriver安装

yum install firefoxwget https://github.com/mozilla/geckodriver/releases/download/v0.23.0/geckodriver-v0.23.0-linux64.tar.gztar xf geckodriver-v0.23.0-linux64.tar.gz -C /usr/binchmod +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.bz2tar xf https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2cd phantomjs-2.1.1-linux-x86_64/binmv 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 aiohttppip3 install cchardet aiodns #字符编码检测库及加速DNS解析的库

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

0