zoukankan      html  css  js  c++  java
  • 无界面模式

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    driver = webdriver.Chrome(chrome_options=chrome_options)
    driver.get("https://cnblogs.com/")
    
    作者:阿啊阿吖丁
    链接:https://www.jianshu.com/p/31f2b63437ed
    來源:简书
    简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
    from selenium.webdriver import Firefox
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.firefox.options import Options
    from selenium.webdriver.support import expected_conditions as expected
    from selenium.webdriver.support.wait import WebDriverWait
    
    if __name__ == "__main__":
        options = Options()
        options.add_argument('-headless')  # 无头参数
        driver = Firefox(executable_path='geckodriver', firefox_options=options)  # 配了环境变量第一个参数就可以省了,不然传绝对路径
        wait = WebDriverWait(driver, timeout=10)
        driver.get('http://www.google.com')
        wait.until(expected.visibility_of_element_located((By.NAME, 'q'))).send_keys('headless firefox' + Keys.ENTER)
        wait.until(expected.visibility_of_element_located((By.CSS_SELECTOR, '#ires a'))).click()
        print(driver.page_source)
        driver.quit()
    
    作者:阿啊阿吖丁
    链接:https://www.jianshu.com/p/31f2b63437ed
    來源:简书
    简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
  • 相关阅读:
    计算机网络体系结构
    牛客多校第一场 Random Point in Triangle
    CSS line-height应用
    CSS line-height与行内框
    CSS 特殊性、继承与层叠
    Javascript进阶(6)---JS函数
    Javascript进阶(5)---闭包
    Javascript进阶(4)---编写类
    Javascript进阶(4)---几种特殊情况分析
    Javascript进阶(3)---原型链1
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10410510.html
Copyright © 2011-2022 走看看