linux下硒铬使用详解

  

安装chrome
  

        wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm   yum安装。/google-chrome-stable_current_x86_64.rpm   yum安装mesa-libOSMesa-devel gnu-free-sans-fonts wqy-zenhei-fonts      之前      

安装chromedriver
  

  

淘宝源(推荐)
  

        wget http://npm.taobao.org/mirrors/chromedriver/2.41/chromedriver_linux64.zip   解压缩chromedriver_linux64.zip   移动chromedriver/usr/bin/chmod + x/usr/bin/chromedriver   之前      

编写硒自动化脚本
  

        # !/usr/bin/python   # - *编码:utf - 8 - *      进口稀土,操作系统   进口json   导入的时间   进口随机   进口的要求   从硒进口webdriver   从硒。webdriver进口ActionChains   从selenium.webdriver.common.by进口   从selenium.webdriver.common.keys导入密钥   从selenium.common.exceptions进口NoSuchElementException   从selenium.webdriver。支持导入expected_conditions EC   从selenium.webdriver.support。等进口WebDriverWait   从selenium.webdriver.support。等进口TimeoutException   从selenium.webdriver.chrome。选择导入选项   从selenium.webdriver.support。选择import选择      binary_location=/usr/bin/google chrome的   chrome_driver_binary='/usr/bin/chromedriver '      chrome_options=选项()   chrome_options。binary_location=binary_location   chrome_options.add_argument (“——no-sandbox”)   chrome_options.add_argument(——无头的)   chrome_options.add_argument (“——disable-gpu”)   chrome_options.add_argument (“——disable-dev-shm-usage”)      chromedriver=chrome_driver_binary   (“webdriver.chrome os.environ。司机"]=chromedriver      浏览器=webdriver。铬(executable_path=/usr/bin/chromedriver, chrome_options=chrome_options)      等待=WebDriverWait(浏览器,5)   URL=" http://www.baidu.com "   BROWSER.get (URL)   ..........      

<强>踩到的坑一:
  

  

中文乱码,解决方法:

  

centos:

        百胜groupinstall字体      ubuntu:

        sudo apt-get安装ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy      

<强>踩到的坑二:
  

  

不能截的图,抛时间异常

  
  

selenium.common.exceptions.TimeoutException:消息:超时:从渲染器超时接收消息:10.000
  

     

解决方法:

        选择=webdriver.ChromeOptions ()   options.add_argument(”——无头”)   options.add_argument (“start-maximized”)   options.add_argument(“实现自动化”)   options.add_argument (”——no-sandbox”)   options.add_argument (”——disable-infobars”)   options.add_argument (”——disable-dev-shm-usage”)   options.add_argument (”——disable-browser-side-navigation”)   options.add_argument (”——disable-gpu”)   司机=webdriver.Chrome (chrome_options=选项)   司机。set_window_size (1024、768)   司机。get_screenshot_as_file (STATIC_FOLDER + home_img_url)   driver.close ()      

到此这篇关于linux下硒铬使用详解的文章就介绍到这了,更多相关linux硒铬内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

linux下硒铬使用详解