You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Guet10086/selenium模块的对搜索框的搜索.py

39 lines
869 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pip install selenium
#下载浏览器驱动,可以使用不同浏览器驱动进行选择
# 定义一个输入字符串str对函数进行输入
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import Edge
# 引入模块
from selenium.webdriver.common.by import By
#
# # 改写方法
# dr.find_element(By.XPATH, "my xpath")
web=Edge()
time.sleep(1)
web.get("https://www.qbiqu.com/")
#找到目标网页然后找到input输入框进行输入---有两种实现模式1.输入回车2.按下搜索按钮
time.sleep(2)
inputweb=web.find_element(By.XPATH,'//*[@id="wd"]').send_keys("冰火魔厨",Keys.ENTER)
time.sleep(2)
web.switch_to.window(web.window_handles[-1])
#使用模块提取到目的书籍的url
url=web.current_url
# url=inputweb.current_url
print(url)
# time.sleep(100)