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()