# -*- coding: utf-8 -*-

import requests
import pyquery
from bs4 import BeautifulSoup
from pyquery import PyQuery

# 化学
link1 = "https://mp.zhizhuma.com/q?c=120FFM3CB61&sh=sh&vt_=1617104397023&_loginTime=1617104400644"
# 生物
line2 = "https://mp.zhizhuma.com/q?c=120FFM55995&sh=sh&vt_=1617111615643"
# 物理
line3 = "https://mp.zhizhuma.com/q?c=120FFM2RE19&sh=sh&vt_=1617111788726"

prefix = "https://mp.zhizhuma.com"


def start():
    resp = requests.get(line3)
    # print(resp.text)
    soup = BeautifulSoup(resp.text, features="html5lib")
    items = soup.select(".chapter-item .sections .section-wrapper")
    # print(len(items))
    for item in items:
        suburl = prefix + item["val"]
        title = item.select_one(".section .text").get_text()
        subresp = requests.get(suburl)
        subsoup = BeautifulSoup(subresp.text, features="html5lib")
        m3u8 = subsoup.select_one("#data_content").get_text()
        print(title + "," + m3u8)
        with open("huaxue.txt", mode="a") as f:
            f.write(title + "," + m3u8)

        # TODO 调用cli


if __name__ == '__main__':
    start()
