How to install the request Library in python3
Editor to share with you how to install the python3 request library, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Environment description
[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 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 Library selenium Library
Pip3 install requestspip3 install selenium
Chromederiver installation
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 95authentication python3 > from selenium import webdriver > browser = webdriver.Chrome () # A blank chrome# pops up by default root users cannot call chrome It is recommended to establish a separate user for chrome
GeckoDriver installation
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# Verification python3 > > from selenium import webdriver > browser = webdriver.Firefox () # will pop up a blank Firefox
Above, we can use chrome or firefox to crawl web pages, but there will be a problem: because the program needs to run with the browser open all the time. So we can choose the browser PhantomJS with × × face.
PhantomJS installation
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# Verification python3 > > from selenium import webdriver > browser = webdriver.PhantomJS () > browser.get ('https://www. Baidu.com') > print (browser.current_url) https://www.baidu.com/>>># now The browser does not open, but the request address is printed through print. It shows that it can be used normally.
Aiohttp installation
Aiohttp is a request library similar to requests, except that aiohttp is a library that provides asynchronous web services.
The installation is as follows:
Pip3 install aiohttppip3 install cchardet aiodns # character Encoding Detection Library and accelerated DNS parsing Library these are all the contents of the article "how to install the request Library for python3". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!