zoukankan      html  css  js  c++  java
  • Selenium之无头模式

    Selenium之无头模式

    from selenium import webdriver
    
    # PhantomJS 无头
    driver = webdriver.PhantomJS(executable_path=r'')
    driver.implicitly_wait(30)
    driver.get('http://www.baidu.com')
    driver.find_element_by_id('kw').send_keys(r'断浪狂刀忆年少-cnblogs')
    driver.find_element_by_id('su').click()
    driver.implicitly_wait(30)  # 隐式等待
    driver.find_element_by_link_text('断浪狂刀忆年少 - 博客园').click()
    driver.save_screenshot('./a.png')  # 可用截取完整的图片
    driver.quit()
    
    # 谷歌无头
    
    from selenium.webdriver.chrome.options import Options
    
    # 创建一个参数对象,用来控制chrome以无界面模式打开
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    
    # 创建浏览器对象
    # driver = webdriver.Chrome(chrome_options=chrome_options)
    # driver.implicitly_wait(30)
    # 访问url
    # driver.get('http://www.baidu.com')
    # print(driver.title)  # 百度一下,你就知道
    # driver.quit()
    
    # 火狐无头
    from selenium.webdriver.firefox.options import Options
    # 创建浏览器对象
    options = Options()
    options.add_argument('-headless')
    driver = webdriver.Firefox(firefox_options=options)
    driver.implicitly_wait(30)
    # 访问url
    driver.get('http://www.baidu.com')
    print(driver.title)  # 百度一下,你就知道
    driver.quit()
    幻想毫无价值,计划渺如尘埃,目标不可能达到。这一切的一切毫无意义——除非我们付诸行动。
  • 相关阅读:
    mysql03聚合函数
    栈、队列、循环队列、双端队列、优先级队列04
    OOAD之策略模式(1)
    jvm01:java内存区域与内存
    Python+Selenium
    Python+Selenium
    Python+Selenium
    Python+Selenium
    Python+Selenium
    Python+Selenium
  • 原文地址:https://www.cnblogs.com/TodayWind/p/14903638.html
Copyright © 2011-2022 走看看