from selenium import webdriver from selenium.webdriver.common.keys import Keys import time
时间: 2023-11-15 10:06:48 浏览: 95
selenium-webdriver
# As an AI language model, I cannot execute code. However, I can help you with the syntax and structure.
# Here is an example of how to use Selenium to automate web browsing:
# Initialize the driver
driver = webdriver.Chrome() # or webdriver.Firefox() or webdriver.Edge()
# Open a webpage
driver.get("https://www.google.com")
# Find an element by name and send keys
search_box = driver.find_element_by_name("q")
search_box.send_keys("selenium")
# Send Enter key to search
search_box.send_keys(Keys.ENTER)
# Wait for the page to load
time.sleep(5)
# Print the page title
print(driver.title)
# Close the browser
driver.quit()
阅读全文