Skip to content

Commit

Permalink
selenium交互自动点击浏览器
Browse files Browse the repository at this point in the history
  • Loading branch information
JLUVicent committed Sep 15, 2021
1 parent f6e4502 commit 8f830ef
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions 27_selenium_交互.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import time
from selenium import webdriver

# 创建浏览器对象
path = 'chromedriver.exe'
browser = webdriver.Chrome(path)

# url
url = 'https://www.baidu.com'

browser.get(url)

time.sleep(2)

# 获取文本框的对象
input = browser.find_element_by_id('kw')

# 在文本框中输入周杰伦
input.send_keys('周杰伦')

time.sleep(2)

# 获取百度一下的按钮
button = browser.find_element_by_id('su')

# 点击按钮
button.click()

time.sleep(2)

# 滑到底部
js_bottom = 'document.documentElement.scrollTop=100000'
browser.execute_script(js_bottom)

time.sleep(2)

# 获取下一页按钮
next = browser.find_element_by_xpath('//a[@class="n"]')

# 点击下一页
next.click()

time.sleep(2)

# 回到上一页
browser.back()

time.sleep(2)

# 回去
browser.forward()

time.sleep(3)

# 退出
browser.quit()

0 comments on commit 8f830ef

Please sign in to comment.