Skip to content

Commit 8074b9d

Browse files
authored
Add files via upload
1 parent 5213c7f commit 8074b9d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

autotry.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Mon Apr 24 10:45:06 2023
4+
5+
@author: Reaper
6+
"""
7+
8+
9+
from selenium import webdriver
10+
from selenium.webdriver.common.keys import Keys
11+
from time import sleep
12+
from selenium.webdriver.common.by import By
13+
14+
# 创建一个 Chrome 浏览器实例
15+
browser = webdriver.Chrome()
16+
17+
# 打开一个搜索引擎的网站
18+
browser.get("https://www.baidu.com/")
19+
20+
# 找到搜索框并输入关键字
21+
search_box = browser.find_element(By.NAME,'wd')
22+
search_box.send_keys("Python")
23+
search_box.send_keys(Keys.RETURN)
24+
25+
# 等待搜索结果加载完成
26+
sleep(5)
27+
28+
# 找到搜索结果的第一条,并点击打开
29+
first_result = browser.find_element(By.CSS_SELECTOR,"#content_left div.result h3.t a")
30+
first_result.click()
31+
input()
32+
# 关闭浏览器
33+
browser.quit()

0 commit comments

Comments
 (0)