在linux系統(tǒng)下部署selenium爬蟲程序介紹
前言
我這里是工作需要把selenium 爬蟲程序部署到Linux 服務(wù)器上面 順便跟大家交流一下 如果有興趣的話可以看一下
一、selenium是什么?
Selenium是一個(gè)用于Web應(yīng)用程序測試的工具。Selenium測試直接運(yùn)行在瀏覽器中,就像真正的用戶在操作一樣, 爬蟲用它來抓取一些js動態(tài)加載的數(shù)據(jù)
二、使用步驟
1.引入庫
代碼如下
from selenium.webdriver import Chrome from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options # 使用無頭瀏覽器 from selenium.webdriver import ChromeOptions chrome_options = Options() options = ChromeOptions() options.add_experimental_option('excludeSwitches', ['enable-automation']) # =>去掉瀏覽器正在受到自動測試軟件的控制 options.add_experimental_option('useAutomationExtension', False) chrome_options.add_argument("--headless") # => 為Chrome配置無頭模式 chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-gpu') chrome_options.add_argument('--disable-dev-shm-usage')
2.測試代碼
代碼如下:
s = Service(r"/home/driver/chromedriver") driver = Chrome( service=s, options=chrome_options ) driver.get("https://www.baidu.com") print(diiver.title)
三、部署程序
1.安裝chrome
命令如下:
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm 檢查chrome的版本 google-chrome --version
2.安裝chromedriver驅(qū)動
命令如下:
按照對應(yīng)的chrome版本下載chromedriver驅(qū)動 地址: https://npm.taobao.org/mirrors/chromedriver 我的版本號是: 96.0.4664.45 wget https://npm.taobao.org/mirrors/chromedriver/96.0.4664.45/chromedriver_linux64.zip yum install -y unzip zip unzip chromedriver_linux64.zip # 解壓zip文件 mkdir driver #新建文件夾用來存放驅(qū)動 chmod 777 driver/chromedriver # 這是權(quán)限 我這里給的是 777
3.運(yùn)行測試代碼
新建test.py文件
vi test.py
保存 test.py run 一下看看
看到這個(gè)我么就算請求成功了
總結(jié)
到此這篇關(guān)于在linux系統(tǒng)下部署selenium爬蟲程序介紹的文章就介紹到這了,更多相關(guān)linux selenium爬蟲程序內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
關(guān)于Apache shiro實(shí)現(xiàn)一個(gè)賬戶同一時(shí)刻只有一個(gè)人登錄(shiro 單點(diǎn)登錄)
今天和同事在一起探討shiro如何實(shí)現(xiàn)一個(gè)賬戶同一時(shí)刻只有一session存在的問題,下面小編把核心代碼分享到腳本之家平臺,需要的朋友參考下2017-09-09Win10 + Ubuntu 16.04雙系統(tǒng)完美安裝教程【詳細(xì)】
這篇文章主要介紹了Win10 + Ubuntu 16.04雙系統(tǒng)完美安裝教程,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10Apache ab并發(fā)負(fù)載壓力測試實(shí)現(xiàn)方法
Apache的ab命令模擬多線程并發(fā)請求,測試服務(wù)器負(fù)載壓力,也可以測試nginx、lighthttp、IIS等其它Web服務(wù)器的壓力2019-09-09LNAMP架構(gòu)中后端Apache獲取用戶真實(shí)IP地址的2種方法
Nginx作為前端,Apache作為后端的情況下,Apache只能獲取到Nginx前端的ip地址(127.0.0.1),而無法獲取到用戶的真實(shí)ip地址,在這種情況下,后端Apache如何獲取用戶真實(shí)IP地址?2014-03-03