zoukankan      html  css  js  c++  java
  • python使用selenium baidu关键词搜索截图

    from selenium import webdriver
    import time
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.chrome.options import Options
    
    url='http://www.baidu.com'
    
    #可能需要指定Chrome路径
    option = Options()
    option.add_argument('--headless')
    option.add_argument('--disable-gpu')
    driver=webdriver.Chrome(chrome_options=option)
    
    driver.get(url)
    
    # text=driver.find_element_by_id('wrapper').text
    # print(text)
    # print(driver.title)
    
    #得到页面的快照,留做证明
    # driver.save_screenshot('index.png')
    
    #id=kw是百度输入框的地址,得到输入框的ui元素后输入字
    word="除尘布袋"
    # driver.find_element_by_id('kw').send_keys(u'word')
    driver.find_element_by_id('kw').send_keys(word)
    
    #id是su的是搜索的按钮,用click方法点击
    driver.find_element_by_id('su').click()
    
    time.sleep(5)
    client_height = driver.execute_script("return document.body.scrollHeight")
    driver.set_window_size(1680,client_height)
    time.sleep(5)
    #得到页面的快照,留做证明
    # driver.save_screenshot('word1.png')
    #返回一组字典,对应于当前会话中可见的cookie
    print(driver.get_cookies())
    
    #清空输入框,clear
    driver.save_screenshot('word3.png')
    #关闭浏览器
    driver.quit()
  • 相关阅读:
    git cmd 命令在已有的仓库重新添加新的文件夹
    google guava Multimap的学习介绍
    JavaScript笔记基础版
    初识hive
    深入学习HBase架构原理
    初识Azkaban
    MapReduce工作流多种实现方式
    Hive 分组问题
    sqoop使用中的小问题
    Sqoop 结合多种系统的具体应用
  • 原文地址:https://www.cnblogs.com/Im-Victor/p/14821644.html
Copyright © 2011-2022 走看看