程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Selenium+python complete Baidu search operation

編輯:Python
import time
from selenium import webdriver
driver=webdriver.Chrome()
# Hidden waiting 
driver.implicitly_wait(10)
driver.get('https://baidu.com/')
# Intercept Baidu button 
btn1=driver.find_element_by_id('su')
btn1.screenshot(r'd:\baidu.png')
input1=driver.find_element_by_id('kw')
# Input qq mailbox 
input1.send_keys('qq mailbox ')
btn=driver.find_element_by_id('su')
btn.click()
# Get Baidu QQ The first email result 
res=driver.find_element_by_id('1').find_element_by_tag_name('a')
print(res.text)
# Save the start interface handles
baidu_handle = driver.current_window_handle
if ' Sign in QQ mailbox ' in res.text:
print('pass')
res.click()
# Screenshot 
#driver.get_screenshot_as_file(r'd:\123.png')
# Switch to webdriver To a new interface ...................
for handle in driver.window_handles:
driver.switch_to.window(handle)
# Determine page title 
if ' Sign in QQ mailbox ' in driver.title:
break
else:
print('fail')
print(res.text)
# Switch back to Baidu page 
driver.switch_to.window(baidu_handle)
time.sleep(3)
driver.refresh()

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved