下载selenium地址 https://googlechromelabs.github.io/chrome-for-testing/#stable

注意对应版本号



# 导入webdriver库
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

s = Service('./chromedriver')
# 启动chrome浏览器
driver = webdriver.Chrome(service=s)
#不显示浏览器
options = webdriver.ChromeOptions()
options.add_argument('--headless')  #
# 打开百度页面
num = 0
for x in booklvl:
    url3 = 'https://www.xxx.com/api/document/preview?document_id=' + str(x) + '&all=1'
    #url3 = 'https://www.xxx.com/api/document/preview/'
    print(url3)
    data = {
        "document_id":str(x),
        "all":1
    }
    driver.get(url3)
    item = driver.find_element(By.CSS_SELECTOR ,"body pre")
    #print(item.text)
    item2 = json.loads(item.text)
    print(item2['data'][0]['format_subsets'])
    title = item2['data'][0]['format_subsets'][0]['title']#卷子的题目
    list = item2['data'][0]['format_subsets'][0]['preview_files']#卷子的多个试卷


    for x in list:
        num += 1
        imgurl = "https:"+x['url']
        askURL(title+str(num),imgurl)
        #askurl是我的一个下载程序 用来下载图片
    time.sleep(3)