ubuntu18.04使用webdriver

ubuntu18.04使用webdriver

sudo apt-get install python3-pip
#安装谷歌浏览器
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*
sudo apt-get -f install
#查看谷歌浏览器版本
google-chrome --version
#去https://npm.taobao.org/mirrors/chromedriver/找和自己安装的谷歌浏览器版本相近的chromedriver安装
wget -N  https://npm.taobao.org/mirrors/chromedriver/...
unzip chromedriver_linux64.zip
ln -s chromedriver /usr/bin/chromedriver
pip3 install selenium

#
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
option = Options()
option.add_argument('no-sandbox')
option.add_argument('disable-dev-shm-usage')
option.add_argument('blink-settings=imagesEnabled=false')  
chrome_options.add_argument('--disable-gpu')
option.set_headless()
driver = webdriver.Chrome(chrome_options=option)
driver.get('https://www.baidu.com')
#源代码网页,可以用re等分析
pageSource = driver.page_source.encode('utf-8')
rate = re.search('', pageSource).group().split( )[0]
print(rate)
print(driver.title)
driver.quit()

你可能感兴趣的:(linux,python,ubuntu,selenium)