# coding:utf-8
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
time.sleep(1)
driver.find_element_by_id("kw").send_keys(u"博客")
time.sleep(1)
bd = driver.find_elements_by_class_name("bdsug-overflow")
for i in bd:
print(i.get_attribute("data-key"))
if len(bd) > 1:
bd[1].click()
# 打印当前页面URL
print(driver.current_url)
else:
print("未获取到匹配的词")
关键:
1.如何定位到所有的联想词
2.如何取所要点击的词