使用selenium获取百度热搜词
import time
from selenium.webdriver import firefox,Firefox,FirefoxOptions
option=FirefoxOptions()
option.add_argument("--headless")
option.add_argument("--no-sandbox")
browser = Firefox(executable_path=r'D:\huohuqudong\geckodriver-v0.26.0-win64\geckodriver.exe',options=option)
url='https://voice.baidu.com/act/virussearch/virussearch?from=osari_map&tab=0&infomore=1'
browser.get(url)
button = browser.find_element_by_css_selector('#ptab-0 > div > div.VirusHot_1-5-5_32AY4F.VirusHot_1-5-5_2RnRvg > section > div')
button.click()
time.sleep(1)
c = browser.find_elements_by_xpath("//*[@id='ptab-0']/div/div[2]/section/a/div/span[2]")
for i in c:
print(i.text)
browser.close()