百度搜索联想词汇

 

联想词汇的class都相同,因此可以很容易定位到

 1 from selenium import webdriver
 2 driver = webdriver.Firefox()
 3 driver.get('https://wwww.baidu.com')
 4 driver.implicitly_wait(2)
 5 driver.find_element_by_id('kw').send_keys('博客')
 6 f = driver.find_elements_by_class_name('bdsug-overflow')
 7 for i in f:
 8     print(i.get_attribute('data-key'))
 9 if len(f)>1:
10     f[1].click()
11     print(driver.current_url)
12 else:
13     print("未获取匹配的词")

 

posted @ 2019-04-22 10:33  yanrufei  阅读(739)  评论(0编辑  收藏  举报