欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

在linux系統(tǒng)下部署selenium爬蟲程序介紹

 更新時(shí)間:2021年11月25日 17:02:04   作者:崔子末  
大家好,本篇文章主要講的是在linux系統(tǒng)下部署selenium爬蟲程序介紹,感興趣的同學(xué)速來圍觀哦,記得收藏本篇文章方便下次瀏覽

前言

我這里是工作需要把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)文章

最新評論