The first step is to find the Scripts under your python installation directory, and open the cmd command window in this folder:
pip install selenium -i https://pypi.douban.com/simple
Enter the above, it is mirrored to douban to download faster
Then open pycharm
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time
# 初始化浏览器
browser = webdriver.Chrome()
try:
browser.get('https://baidu.com')
# 通过 id 找到input框
input = browser.find_element(By.CSS_SELECTOR, '#kw')
# 输入python
input.send_keys('前端开发')
input.send_keys(Keys.ENTER) # 按下回车键
# 设置等待id为 content_left 的元素
wait = WebDriverWait(browser, 10) # 等待browser对象都为10秒
# presence_of_element_located 表示定位元素
wait.until(EC.presence_of_element_located((By.ID, 'content_left')))
time.sleep(10)
finally:
browser.close()
can achieve this function