12345678910111213141516171819202122232425262728293031323334353637 |
- # -*- coding: utf-8 -*-
- # @Author: wangkun
- # @Time: 2022/10/25
- import time
- from selenium.webdriver import DesiredCapabilities
- from selenium.webdriver.common.by import By
- from seleniumwire import webdriver
- class Demo:
- @classmethod
- def get_hotword(cls):
- # 打印请求配置
- ca = DesiredCapabilities.CHROME
- ca["goog:loggingPrefs"] = {"performance": "ALL"}
- # driver初始化
- driver = webdriver.Chrome(desired_capabilities=ca)
- # driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options)
- driver.implicitly_wait(10)
- print('打开百度网页')
- driver.get('https://www.baidu.com/')
- driver.maximize_window()
- driver.implicitly_wait(10)
- time.sleep(1)
- hot_words = driver.find_elements(By.XPATH, '//li[@class="hotsearch-item odd"]')
- for i in range(len(hot_words)):
- print(i)
- hot_word = hot_words[i].find_element(By.XPATH, '//span[@class="title-content-title"]')
- print(hot_word)
- if __name__ == '__main__':
- Demo.get_hotword()
|