触发搜索

对于想要触发百度首页中的搜索来说,除了点击元素外,还可以模拟输入回车键

  • 触发百度搜索
    • 方式1:点击百度一下按钮
      BaiduSearchId = "su"
      baiduSearchButtonElem = chromeDriver.find_element_by_id(BaiduSearchId)
      baiduSearchButtonElem.click()
      
    • 方式2:模拟输入回车键
      from selenium.webdriver.common.keys import Keys
      # Method 1: emulate press Enter key
      searchButtonElem.send_keys(Keys.RETURN)
      

附上:模拟百度输入并搜索的相关代码

searchStr = "crifan"
searchButtonElem.send_keys(searchStr)
print("Entered %s to search box" % searchStr)

# click button
# Method 1: emulate press Enter key
# searchButtonElem.send_keys(Keys.RETURN)
# print("Pressed Enter/Return key")

# Method 2: find button and click
BaiduSearchId = "su"
baiduSearchButtonElem = chromeDriver.find_element_by_id(BaiduSearchId)
print("baiduSearchButtonElem=%s" % baiduSearchButtonElem)
baiduSearchButtonElem.click()
print("Clicked button %s" % baiduSearchButtonElem)

results matching ""

    No results matching ""