centos 安裝Selenium+Chrome

來源:互聯網
上載者:User

標籤:driver   org   spider   x11   ble   browser   pre   listen   site   

參照https://cuiqingcai.com/4886.html

1234 ## 安裝yum源[root@spider01 ~]# sudo yum install -y epel-release## 安裝Chrome[root@spider01 ~]# yum install -y chromium

 

 

去這個地方:https://sites.google.com/a/chromium.org/chromedriver/downloads 下載ChromeDriver驅動放在/usr/bin/目錄下:

完成結果如下:

Shell 
123 [root@spider01 ~]# ll /usr/bin/ | grep chrom-rwxrwxrwx. 1 root root   7500280 11月 29 17:32 chromedriverlrwxrwxrwx. 1 root root        47 11月 30 09:35 chromium-browser -> /usr/lib64/chromium-browser/chromium-browser.sh

安裝XVFB:

12 [root@spider01 ~]# yum install Xvfb -y[root@spider01 ~]# yum install xorg-x11-fonts* -y

建立在/usr/bin/ 一個名叫 xvfb-chromium 的檔案寫入以下內容:

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 :99 -ac -screen 0 $XVFB_WHD -nolisten tcp &xvfb=$! export DISPLAY=:99 chromium --no-sandbox --disable-gpu$@ &chromium=$! wait $chromiumwait $xvfb

更改軟串連:

Shell 
1234567891011121314151617 ## 更改Chrome啟動的軟串連[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 11月 29 17:32 chromedriverlrwxrwxrwx. 1 root root        47 11月 30 09:47 chromium -> /usr/lib64/chromium-browser/chromium-browser.shlrwxrwxrwx. 1 root root        22 11月 30 09:48 chromium-browser -> /usr/bin/xvfb-chromium-rwxr-xr-x. 1 root root     73848 12月  7 2016 chronyclrwxrwxrwx. 1 root root        22 11月 30 09:48 google-chrome -> /usr/bin/xvfb-chromium-rwxrwxrwx. 1 root root       387 11月 29 18:16 xvfb-chromium
Shell 
123456 >>> from selenium import webdriver>>> driver = webdriver.Chrome()>>> driver.get("http://www.baidu.com")>>> driver.find_element_by_xpath("./*//input[@id=‘kw‘]").send_keys("哎喲臥槽")>>> driver.find_element_by_xpath("./*//input[@id=‘su‘]").click()>>> driver.page_source

centos 安裝Selenium+Chrome

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.