使用webdriver进行爬虫、自动化操作时不显示浏览器运行。
# -*- coding:utf-8 -*-
"""
project: test_test
file: m3u8
author: WangPanPan
create date: 2022/5/30 19:31
"""
from selenium.webdriver.chrome.options import Options
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
#参考的网页
base_url = 'https://jingyan.baidu.com/article/00a07f38500e2bc3d028dcd3.html'
# 使用webdriver
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
driver.get(base_url)
three = driver.find_element(By.XPATH,'//*[@id="format-exp"]/div[3]/div/ol/li[3]/div[2]/p').text
print(three)
driver.quit()