# coding:utf-8
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
import json

if __name__ == "__main__":
    chrome_options=Options()
    chrome_options.add_argument('--headless')
    browser = webdriver.Chrome(chrome_options=chrome_options)
    browser.get('https://m.baidu.com/s?word=%E6%AD%A6%E6%B1%89%E8%82%BA%E7%82%8E')
    browser.implicitly_wait(20)
    scripts = browser.find_elements_by_xpath('//script[@type="application/json"]')
    for item in scripts:
        j = json.loads(item.get_attribute('innerHTML'))
        if 'data' in j:
            if 'title' in j["data"] and j['data']['title'] == "事件脉络":
                for es in j['data']['items']:
                    print(es['item_time_date']," ",es['eventDescription'])
    print(len(scripts))
    print(browser.title)

数据来源:百度搜索【关键字:武汉肺炎】

WX20200121-191448@2x.png