IT评测·应用市场-qidao123.com技术社区

标题: selenium学习笔记 [打印本页]

作者: 郭卫东    时间: 2025-1-10 11:51
标题: selenium学习笔记
一.搭建环境

1.安装chrome

  1. #下载chrome
  2. wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
  3. #安装chrome
  4. apt --fix-broken install ./google-chrome-stable_current_amd64.deb
复制代码
2.安装chromedriver

起首先查察版本:google-chrome --version
前去Chrome for Testing availability
 下载对应版本号的driver
  1. #下载
  2. wget https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.86/linux64/chrome-linux64.zip
  3. #执行
  4. unzip chromedriver-linux64.zip
  5. cd chromedriver-linux64
  6. mv chromedriver /usr/bin
复制代码
3.核对版本号是否同等

  1. #
  2. google-chrome --version
  3. #
  4. chromedriver --version
复制代码
4.调试

  1. from selenium import webdriver                                       
  2. chrome_options = webdriver.ChromeOptions()
  3. chrome_options.add_argument('--headless')
  4. chrome_options.add_argument('--no-sandbox')
  5. chrome_options.add_argument('--disable-gpu')
  6. chrome_options.add_argument('--disable-dev-shm-usage')
  7. driver = webdriver.Chrome(options=chrome_options)
  8. url = "https://baidu.com"
  9. driver.get(url)
  10. print(driver.title)
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com技术社区 (https://dis.qidao123.com/) Powered by Discuz! X3.4