栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

selenium ubuntu

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

selenium ubuntu

系列文章目录

selenium


selenium ubuntu
  • 系列文章目录
  • 前言
  • 一、ubuntu
  • 二、使用
    • 1.chromedriver
    • 2.python3
    • 3.selenium
    • 4.测试
  • 参考


前言

selenium ubuntu


一、ubuntu
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb
# which google-chrome
/usr/bin/google-chrome
# google-chrome --version
Google Chrome 102.0.5005.61
二、使用 1.chromedriver
# wget https://chromedriver.storage.googleapis.com/102.0.5005.61/chromedriver_linux64.zip
# unzip chromedriver_linux64.zip
2.python3
# ls -lh /usr/bin/ | grep python
lrwxrwxrwx 1 root   root       9 Mar 13  2020 python3 -> python3.8
-rwxr-xr-x 1 root   root    5.3M Apr 27  2020 python3.8
# pwd
/usr/bin
# ln -s python3.8 python
# apt install python3-pip -y
3.selenium
pip install selenium
4.测试
from selenium import webdriver

chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox') # 这个配置很重要

#client = webdriver.Chrome(chrome_options=chrome_options, executable_path='/usr/bin/chromedriver')    # 如果没有把chromedriver加入到PATH中,就需要指明路径
client = webdriver.Chrome(options=chrome_options)    # 如果没有把chromedriver加入到PATH中,就需要指明路径

client.get("https://www.baidu.com")

print (client.page_source.encode('utf-8'))
client.quit()
  • 测试2
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
#options.binary_location = '/usr/bin/google-chrome'
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')

driver = webdriver.Chrome(options=options)

url = 'http://www.zhihu.com'
driver.get(url)
#print(driver.page_sources)
print(driver.page_source.encode('utf-8'))

driver.quit()

参考
  1. 如何在 Ubuntu 20.04 上安装 Google Chrome 网络浏览器
  2. Ubuntu 配置selenium+chrome headless环境
  3. Ubuntu 无界面使用selenium chrome + headless
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/950471.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号