Reference https://cuiqingcai.com/4886.html
1234 |
# # Install the Yum source [root@spider01 ~]# sudo yum install-y epel-release # # Install chrome[root@spider01 ~]# yum Install-y chromium |
Go to this place: Https://sites.google.com/a/chromium.org/chromedriver/downloads Download the Chromedriver driver in the/usr/bin/directory:
The completed results are as follows:
Shell
123 |
[root@spider01 ~]# ll/usr/bin/| grep chrom -rwxrwxrwx. 1 root root 7500280 November : Chromedriver lrwxrwxrwx. 1 RootRoot November : chromium-browser usr/lib64/chromium-browser/chromium-browser. sh |
Install XVFB:
12 |
[root@spider01 ~]# yum install xvfb-y [root@spider01 ~]# yum Install xorg-x11-fonts*-y |
New in/usr/bin/a file named Xvfb-chromium writes the following:
Shell
12345678910111213141516171819202122232425 |
[root@spider01 ~]# cat/usr/bin/xvfb-chromium #!/bin/bash_kill_procs() { kill -term $chromium wait $chromium kill -term $xvfb }# Setup A trap to catch SIGTERM and relay it to child processestrap _kill_procs SIGTERM XVFB_WHD=${XVFB_WHD:-1280x720x16} # Start XvfbXvfb :- ac -screen 0 $XVFB _whd - Nolisten TCP & Xvfb=$! export DISPLAY=: Chromium-- no-sandbox- -Disable-GPU$@ & Chromium=$! wait $chromium wait $xvfb |
To change a soft connection:
Shell
1234567891011121314151617 |
# # Change chrome-enabled soft connect[root@spider01 ~]# ln-s/usr/lib64/chromium-browser/chromium-browser.sh/usr/bin/ Chromium [root@spider01 ~]# rm-rf/usr/bin/chromium-browser [root@spider01 ~]# ln-s/usr/bin/xvfb-chromium/usr/bin/chromium-browser [root@spider01 ~]# ln-s/usr/bin/xvfb-chromium/usr/bin/google-chrome [root@spider01 ~]# ll/usr/bin/| grep chrom* -rwxrwxrwx. 1 root root 7500280 November : Chromedriver lrwxrwxrwx. 1 RootRoot November : chromium /USR / lib64/chromium-browser/chromium-browser. SH lrwxrwxrwx. 1 root root 22 11 month 30 09:48 chromium-browser Span class= "Crayon-o" >-> /usr/bin/xvfb -chromium -rwxr-XR-x. 1 root root 73848 December 7 chronyc /c19> lrwxrwxrwx. 1 root root 22 11 month 30 09:48 google-chrome -> /usr /bin/xvfb-chromium -rwxrwxrwx. 1 root root 387 November : xvfb- chromium |
Shell
123456 |
>>> from selenium import webdriver >>> driver = webdriver. Chrome() >>> driver. Get("http://www.baidu.com") >>> driverfind_element_by_xpath("./*//input[@id = ' kw ']"). Send_keys ("Ouch-trough") >>> driver. Find_element_by_xpath("./*//input[@id = ' su ']"). Click ()>>> driver. Page_source |
CentOS Installation Selenium+chrome