123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666 |
- package student
- import (
- "bufio"
- "bytes"
- "encoding/json"
- "errors"
- "fmt"
- "github.com/tebeka/selenium"
- "github.com/tebeka/selenium/chrome"
- "github.com/tidwall/gjson"
- "io"
- "io/ioutil"
- "net/http"
- "os"
- "strconv"
- "strings"
- "time"
- )
- func GetAcounts(filename string) ([][]string, error) {
- fi, err := os.Open(filename)
- if err != nil {
- return nil, err
- }
- defer fi.Close()
- ret := [][]string{}
- br := bufio.NewReader(fi)
- for {
- a, _, c := br.ReadLine()
- if c == io.EOF {
- break
- }
- array := strings.Split(string(a), ";")
- if len(array) != 3 {
- continue
- }
- item := []string{array[0], array[1], array[2]}
- ret = append(ret, item)
- }
- return ret, nil
- }
- func Displayed(by, elementName string) func(selenium.WebDriver) (bool, error) {
- return func(wd selenium.WebDriver) (ok bool, err error) {
- var el selenium.WebElement
- el, err = wd.FindElement(by, elementName)
- if err != nil {
- ok = false
- err = nil
- return
- }
- ok, err = el.IsDisplayed()
- return
- }
- }
- func StartOneStudent(usernameText string, passwordText string, realName string) (*selenium.Service, selenium.WebDriver, error) {
- // TODO 更改路径
- var (
- //driverPath = `C:\Users\lqzlt\AppData\Local\Google\Chrome\Application\chromedriver.exe`
- driverPath = `chromedriver.exe`
- port = 60002
- )
- service, err := selenium.NewChromeDriverService(driverPath, port, []selenium.ServiceOption{}...)
- if nil != err {
- return nil, nil, err
- }
- defer func() {
- //_ = service.Stop()
- }()
- // Connect to the WebDriver instance running locally.
- caps := selenium.Capabilities{"browserName": "chrome"}
- //禁止图片加载,加快渲染速度
- imagCaps := map[string]interface{}{
- //"profile.managed_default_content_settings.images": 2,
- //"profile.default_content_setting_values":2,
- "same-site-by-default-cookies":2,
- "cookies-without-same-site-must-be-secure":2,
- }
- chromeCaps := chrome.Capabilities{
- Prefs: imagCaps,
- Path: "",
- ExcludeSwitches:[]string{"enable-automation"},
- //Extensions:[]string{"D:\\sql2struct"},
- Args: []string{
- //"--headless",
- //"--disable-javascript",
- "--no-sandbox",
- "--disable-gpu-sandbox",
- "--accept-Encoding=gzip, deflate",
- "--accept-language=zh-CN,zh;q=0.9,zh-TW;q=0.8,en-US;q=0.7,en;q=0.6",
- "--cache-control=max-age=0",
- "--abc=d",
- "--load-extention=D:\\sql2struct",
- //"--cookie=MoodleSession=66925citrm0o6b68gsfn9quaof;username=2051101450211;UserName=2051101450211",
- "--moodleSession=66925citrm0o6b68gsfn9quaof;username=2051101450211",
- "--upgrade-insecure-requests=1",
- //"--authorization=Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IkYyREVCM0ZGMURBMUFEODNFOTA5QjIxMjM4QTZCMjU5RjAyQjNGMDEiLCJ0eXAiOiJKV1QiLCJ4NXQiOiI4dDZ6X3gyaHJZUHBDYklTT0theVdmQXJQd0UifQ.eyJuYmYiOjE2MzYwMTAzNTMsImV4cCI6MTYzNjAxMzk1MywiaXNzIjoiaHR0cDovL3Bhc3Nwb3J0Lm91Y2huLmNuIiwiYXVkIjpbImh0dHA6Ly9wYXNzcG9ydC5vdWNobi5jbi9yZXNvdXJjZXMiLCJvdWNobnN0dWRlbnRzcGFjZWFwaSJdLCJjbGllbnRfaWQiOiJzdHVkZW50c3BhY2UiLCJzdWIiOiJlZjkzZTdlYi0zYjhlLTQ2ZTUtYjA1ZC1mYTJmYjAwYjA2ZmUiLCJhdXRoX3RpbWUiOjE2MzYwMTAyMDMsImlkcCI6ImxvY2FsIiwibmFtZSI6IjIwNTExMDE0NTAyMTEiLCJVc2VySWQiOiJlZjkzZTdlYi0zYjhlLTQ2ZTUtYjA1ZC1mYTJmYjAwYjA2ZmUiLCJVc2VyTmFtZSI6IjIwNTExMDE0NTAyMTEiLCJuaWNrbmFtZSI6IueOi-aVjyIsIkF2YXRhciI6IiIsIlVzZXJUeXBlIjoiMiIsIlByb3ZpbmNlU2Nob29sQ29kZSI6IjUxMSIsIk9yZ2FuaXphdGlvbkNvZGUiOiI1MTE1NDAwIiwiTW9iaWxlQ29uZmlybWVkIjoiRmFsc2UiLCJzY29wZSI6WyJvcGVuaWQiLCJwcm9maWxlIiwib3VjaG51c2VyIiwib3VjaG5zdHVkZW50c3BhY2VhcGkiLCJvZmZsaW5lX2FjY2VzcyJdLCJhbXIiOlsicHdkIl19.ACwdaY50NnuXiQso4T6dS1PoQc7K2rTBRKWz0VmocC40xL4PlPy3Usf3kAZf-1dNFnh8PTBUWc9s_F6eTp_Rcemu5IBGL-iKs9I-QMeG3u7TnaNbCL4XwUt8vZoOPHaXzor3gN7WEqs01Qj11nTbERZ2ixEMhk2Ov_lGqCS8me67pyvd2HWCP7yUcizfEk4_5FQBZZ12daRpXrBksCC27I8BcpXQLrogWewa1W4x5uhLFeW7BKhBGxYDT4yM-b0RNM2jNTxn-ToqoOgBIsLsnU8e0eOKi6WBuhbDYK8psiCPt1hT_3BumeuJ-P36iuaPLcNv7D2T1WlCMHJe1Fv92Q",
- "--connection=keep-alive",
- //"--host=chengdu.ouchn.cn",
- "--accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
- "--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36",
- },
- }
- //以上是设置浏览器参数
- caps.AddChrome(chromeCaps)
- wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))
- if err != nil {
- return service, nil, errors.New(fmt.Sprintf("connect to the webDriver failed:%v\n", err))
- }
- //time.Sleep(120*time.Second)
- defer func() {
- //time.Sleep(60*time.Second)
- //fmt.Printf("!! quit window\n")
- //_ = wd.Close()
- }()
- err = wd.Get("http://www.ouchn.cn/#")
- if err != nil {
- return service, wd, err
- }
- //fmt.Printf("1111111\n")
- err = wd.WaitWithTimeout(Displayed(selenium.ByXPATH, "//button[text()='学生登录']"), 10*time.Second)
- if err != nil {
- return service, wd, errors.New(fmt.Sprintf("获取学生登录按钮失败:%v\n", err))
- }
- //fmt.Printf("111112\n")
- button, err := wd.FindElement(selenium.ByXPATH, "//button[text()='学生登录']")
- if err != nil {
- return service, wd, errors.New(fmt.Sprintf("获取学生登录按钮失败:%v\n", err))
- }
- err = button.Click()
- //time.Sleep(1000*time.Second)
- //fmt.Printf("11113:%v\n", err)
- err = wd.WaitWithTimeout(Displayed(selenium.ByID, "loginbth"), 5*time.Second)
- if err != nil {
- return service, wd, errors.New(fmt.Sprintf("获取登录页面失败:%v\n", err))
- }
- //fmt.Printf("11114\n")
- username, err := wd.FindElement(selenium.ByID, "username")
- if err != nil {
- return service, wd,errors.New(fmt.Sprintf("获取用户名按钮:%v\n", err))
- }
- password, err := wd.FindElement(selenium.ByID, "password")
- if err != nil {
- return service, wd,errors.New(fmt.Sprintf("获取密码按钮:%v\n", err))
- }
- submit, err := wd.FindElement(selenium.ByID, "loginbth")
- if err != nil {
- return service, wd,errors.New(fmt.Sprintf("获取登录按钮:%v\n", err))
- }
- err = username.SendKeys(usernameText)
- if err != nil {
- return service, wd,errors.New(fmt.Sprintf("填充用户名:%v\n", err))
- }
- err = password.SendKeys(passwordText)
- if err != nil {
- return service, wd,errors.New(fmt.Sprintf("填充密码:%v\n", err))
- }
- err = submit.Click()
- if err != nil {
- return service, wd,errors.New(fmt.Sprintf("点击登录:%v\n", err))
- }
- err = wd.WaitWithTimeout(Displayed(selenium.ByXPATH, "//button[text()='进入学习']"), 5*time.Second)
- if err != nil {
- return service, wd,errors.New(fmt.Sprintf("进入学生主页失败:%v\n", err))
- }
- buttons, _ := wd.FindElements(selenium.ByTagName, "button")
- currentWindow, err := wd.CurrentWindowHandle()
- if err != nil {
- return service, wd,errors.New(fmt.Sprintf("获取当前窗口失败:%v\n", err))
- }
- //fmt.Printf("xxx:%d\n", len(buttons))
- for _, button := range buttons {
- text, _ := button.Text()
- if text != "进入学习" {
- continue
- }
- //fmt.Printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n")
- button.Click()
- //time.Sleep(60*time.Second)
- count := 0
- handled := ""
- for count < 5 {
- time.Sleep(1*time.Second)
- handles, _ := wd.WindowHandles()
- if len(handles) > 1 {
- handled = handles[len(handles)-1]
- wd.SwitchWindow(handled)
- break
- }
- count++
- }
- if count > 5 {
- continue
- }
- CourseHandle(wd, realName)
- wd.CloseWindow(handled)
- err = wd.SwitchWindow(currentWindow)
- //fmt.Printf("switch window:%v\n", err)
- }
- return service, wd, nil
- }
- func waitUrl(wd selenium.WebDriver, url1 string, url2 string, count int) string {
- for count >= 0 {
- time.Sleep(100 *time.Millisecond)
- url, _ := wd.CurrentURL()
- if url != url1 && url != url2 {
- return url
- }
- count--
- }
- return ""
- }
- func getSectionIdFromUrl(url string) (string, string, string) {
- array := strings.Split(url, "?")
- if len(array) != 2 {
- return "", "", ""
- }
- array = strings.Split(array[1], "&")
- if len(array) != 3 {
- return "", "", ""
- }
- couseId := ""
- sectionId := ""
- mid := ""
- for _, v := range array {
- subArray := strings.Split(v, "=")
- if len(subArray) != 2 {
- continue
- }
- if subArray[0] == "id" {
- couseId = subArray[1]
- continue
- }
- if subArray[0] == "sectionid" {
- sectionId = subArray[1]
- continue
- }
- if subArray[0] == "mid" {
- mid = subArray[1]
- }
- }
- return couseId, sectionId, mid
- }
- type secIdInfo struct {
- Id string
- Number int
- }
- func BubbleAsort(values []secIdInfo) {
- for i := 0; i < len(values)-1; i++ {
- for j := i+1; j < len(values); j++ {
- if values[i].Number>values[j].Number{
- values[i],values[j] = values[j],values[i]
- }
- }
- }
- }
- func GetSections(courseId string, sectionId string, cookie string, url string) ([]string, error) {
- str := fmt.Sprintf("sectionid=%s&courseid=%s", sectionId, courseId)
- //fmt.Printf("get sections:%v,%v\n", str, cookie)
- reader := bytes.NewReader([]byte(str))
- request, err := http.NewRequest("POST", url+"/sectionInfo.php", reader)
- if err != nil {
- return nil, err
- }
- //request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
- request.Header.Set("Cookie", cookie)
- request.Header.Set("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36")
- request.Header.Set("Host", "chengdu.ouchn.cn")
- //request.Header.Set("Content-Type","application/x-www-form-urlencoded; charset=UTF-8")
- request.Header.Set("Referer", "http://chengdu.ouchn.cn/course/view.php?id=3257§ionid=129167&mid=375459")
- request.Header.Set("Origin", "http://chengdu.ouchn.cn")
- //request.Header.Set("Accept-Encoding", "gzip, deflate")
- request.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,zh-TW;q=0.8,en-US;q=0.7,en;q=0.6")
- request.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36")
- request.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
- request.Header.Set("Accept", "*/*")
- request.Header.Set("X-Requested-With","XMLHttpRequest")
- request.Header.Set("Connection", "keep-alive")
- client := http.Client{}
- resp, err := client.Do(request)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
- respBytes, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return nil, err
- }
- //fmt.Printf("origin origin%s\n", respBytes)
- m := map[string]interface{}{}
- json.Unmarshal(respBytes, &m)
- t, ok := m["secinfo"]
- if !ok {
- return nil, errors.New("can not find secinfo")
- }
- sec, ok := t.(map[string]interface{})
- if !ok {
- return nil, errors.New("can not convert secinfo")
- }
- ret := []string{}
- secArray := []secIdInfo{}
- tmpArray := []string{}
- //fmt.Printf("sec origin:%v\n", sec)
- for k, v := range sec {
- tt, ok := v.(map[string]interface{})
- if !ok {
- continue
- }
- if id, ok := tt["id"]; ok {
- if ids, ok2 := id.(string); ok2 && ids != "" {
- //ret = append(ret, ids)
- digit, _ := strconv.Atoi(k)
- if digit > 0 {
- secArray = append(secArray, secIdInfo{Id:ids, Number:digit})
- } else {
- tmpArray = append(tmpArray, ids)
- }
- }
- }
- }
- BubbleAsort(secArray)
- for _, v := range secArray {
- ret = append(ret, v.Id)
- }
- ret = append(ret, tmpArray...)
- return ret, nil
- }
- type McidInfo struct {
- Id string
- Name string
- }
- func GetCourseSectionVediosAndQuiz(courseId string, sectionId string, cookie string, url string)([]McidInfo, []McidInfo, error){
- //fmt.Printf("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n")
- str := fmt.Sprintf("sectionid=%s&courseid=%s", sectionId, courseId)
- reader := bytes.NewReader([]byte(str))
- request, err := http.NewRequest("POST", url+"/sectionInfo.php", reader)
- if err != nil {
- return nil, nil, err
- }
- request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
- request.Header.Set("Cookie", cookie)
- request.Header.Set("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36")
- request.Header.Set("Host", "chengdu.ouchn.cn")
- client := http.Client{}
- resp, err := client.Do(request)
- if err != nil {
- return nil, nil, err
- }
- defer resp.Body.Close()
- respBytes, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return nil, nil, err
- }
- // fmt.Printf("content:%s,%s\n", cookie, respBytes)
- m := map[string]interface{}{}
- json.Unmarshal(respBytes, &m)
- vedio := []McidInfo{}
- quiz := []McidInfo{}
- vm := map[string]McidInfo{}
- qm := map[string]McidInfo{}
- for k, v := range m {
- t, ok := v.(map[string]interface{})
- if !ok {
- continue
- }
- if isCom, ok := t["is_com"]; !ok {
- continue
- } else {
- x := fmt.Sprintf("%v", isCom)
- if strings.Contains(x, "1") || strings.Contains(x, "true") {
- continue
- }
- }
- if videourl, ok := t["videourl"]; ok && videourl != ""{
- //fmt.Printf("%v,%v\n", t["name"], t["is_com"])
- name := fmt.Sprintf("%v", t["name"])
- if !strings.Contains(name, "视频") {
- //continue
- }
- if k == "378172" {
- //fmt.Printf("sec:%v\n", sectionId)
- }
- vedio = append(vedio, McidInfo{Id:k, Name:name})
- vm[k] = McidInfo{Id:k, Name:name}
- continue
- }
- if ttype, ok := t["type"]; ok && ttype == "quiz" {
- name := fmt.Sprintf("%v", t["name"])
- quiz = append(quiz, McidInfo{Id:k, Name:name})
- qm[k] = McidInfo{Id:k, Name:name}
- }
- }
- array := gjson.GetBytes(respBytes, "sequence").Array()
- sec := []string{}
- for _, v := range array {
- str := v.String()
- subArray := strings.Split(str, ",")
- for _, sv := range subArray {
- sec = append(sec, sv)
- }
- }
- vedio = make([]McidInfo, len(vm))
- quiz = make([]McidInfo, len(qm))
- i := 0
- j := 0
- for _, v := range sec {
- if info, ok := vm[v]; ok{
- vedio[i] = info
- i++
- continue
- }
- if info, ok := qm[v]; ok {
- quiz[j] = info
- j++
- }
- }
- return vedio, quiz, nil
- }
- func getCookies(wd selenium.WebDriver) (string, error) {
- cookies, err := wd.GetCookies()
- if err != nil {
- return "", errors.New(fmt.Sprintf("获取cookie 失败,%v\n", err))
- }
- if len(cookies) == 0 {
- return "", errors.New(fmt.Sprintf("获取cookie 失败,%v\n", "cookie为空"))
- }
- ret := ""
- for _, v := range cookies {
- item := fmt.Sprintf("%s=%s", v.Name, v.Value)
- if ret == "" {
- ret = item
- continue
- }
- ret = ret + ";"
- ret = ret + item
- }
- return ret, nil
- }
- func getSectionIds(wd selenium.WebDriver, cookie string) (string, []string, string, error) {
- handledUrl := map[string]bool{}
- sectionIdM := map[string]bool{}
- datas, err := wd.FindElements(selenium.ByXPATH, "//a[@class='aalink' and contains(@href, 'chengdu.ouchn.cn/mod/page')]")
- if err != nil {
- return "", nil, "", errors.New(fmt.Sprintf("获取课程详细页面失败%v\n", err))
- }
- urls := make([]string, len(datas))
- for i, data := range datas {
- url,_ := data.GetAttribute("href")
- if url != "" {
- urls[i] = url
- }
- }
- //fmt.Printf("urls:%v\n", urls)
- for i, url := range urls {
- if i >= 5 {
- return "", nil, "", errors.New("未找到section")
- }
- currentUrl, _ := wd.CurrentURL()
- if handledUrl[url] {
- continue
- }
- //fmt.Printf("url:%v\n", url)
- err = wd.Get(url)
- handledUrl[url] = true
- time.Sleep(2*time.Second)
- if err != nil {
- continue
- }
- newUrl := waitUrl(wd, currentUrl, url, 20)
- if !strings.Contains(newUrl, "id=") ||
- !strings.Contains(newUrl, "sectionid=") ||
- !strings.Contains(newUrl, "mid=") {
- continue
- }
- courseId, sectionId,_ := getSectionIdFromUrl(newUrl)
- if courseId == "" || sectionId == "" {
- continue
- }
- if sectionIdM[sectionId] {
- continue
- }
- link, err := wd.FindElement(selenium.ByXPATH, "//link[contains(@href, 'chengdu.ouchn.cn/theme/blueonionre')]")
- if err != nil {
- continue
- }
- href, _ := link.GetAttribute("href")
- baseUrl := "http://chengdu.ouchn.cn/theme/blueonionre"
- if strings.Contains(href, "blueonionres") {
- baseUrl = "http://chengdu.ouchn.cn/theme/blueonionres"
- }
- sections, err := GetSections(courseId, sectionId, cookie, baseUrl)
- if err != nil {
- return "", nil, "", errors.New(fmt.Sprintf("获取section失败%v\n", sections))
- }
- if len(sections) > 0 {
- //fmt.Printf("xxxxxxx url:%v\n", url)
- //time.Sleep(100*time.Second)
- return courseId, sections, baseUrl, nil
- }
- time.Sleep(1*time.Second)
- }
- return "", nil, "", errors.New("位找到section")
- }
- func vedioCompleteUrl(cmid string, id string, sectionid string) string {
- //http://chengdu.ouchn.cn/theme/blueonionre/modulesCompletion.php?cmid=271461&id=2564§ionid=92046
- return fmt.Sprintf("http://chengdu.ouchn.cn/theme/blueonionre/modulesCompletion.php?cmid=%s&id=%s§ionid=%s", cmid, id, sectionid)
- }
- func vedioComplete(wd selenium.WebDriver, cmid string, id string, sectionid string) {
- fmt.Printf("vedio compliete:%s\n", vedioCompleteUrl(cmid, id, sectionid))
- wd.Get(vedioCompleteUrl(cmid, id, sectionid))
- //fmt.Printf("vedioComplete err:%v\n", err)
- time.Sleep(10*time.Second)
- }
- func CourseHandle(wd selenium.WebDriver, username string) error {
- cookie, err := getCookies(wd)
- if err != nil {
- return err
- }
- title, err := wd.Title()
- if title == "" {
- return nil
- }
- if err == nil {
- title = strings.TrimPrefix(title, "课程:")
- }
- if !strings.Contains(title, "习近平新时代中国特色社会主义思想") &&
- !strings.Contains(title, "毛泽东思想和中国特色社会主义理论体系概论") &&
- !strings.Contains(title, "马克思主义基本原理概论") &&
- !strings.Contains(title, "思想道德与法治") &&
- !strings.Contains(title, "思想道德修养与法律基础") {
- return nil
- }
- fmt.Printf("***************正在处理%s课程%s\n", username, title)
- //return nil
- courseId, sections, baseURL, err := getSectionIds(wd, cookie)
- if err != nil {
- return err
- }
- fmt.Printf("sections:%v\n", sections)
- //time.Sleep(100*time.Second)
- vedioM := map[string][]McidInfo{}
- quizM := map[string][]McidInfo{}
- for _, v := range sections {
- time.Sleep(1*time.Second)
- vedios, quiz, err := GetCourseSectionVediosAndQuiz(courseId, v, cookie, baseURL)
- if err != nil {
- //fmt.Printf("GetCourseSectionVediosAndQuiz err:%v\n", err)
- continue
- }
- if len(vedios) > 0 {
- vedioM[v] = vedios
- }
- if len(quiz) > 0 {
- quizM[v] = quiz
- }
- }
- //fmt.Printf("vedioM:%v\n", vedioM)
- for _, sec := range sections {
- mids := vedioM[sec]
- //fmt.Printf("vedioM:%v\n", vedioM)
- for _, mid := range mids {
- fmt.Printf("%s 视频开始处理\n", mid.Name)
- url := fmt.Sprintf("http://chengdu.ouchn.cn/mod/url/view.php?id=%s", mid.Id)
- //fmt.Printf("手动url:%s\n", url)
- current, _ := wd.CurrentURL()
- wd.Get(url)
- newUrl := waitUrl(wd, current, url, 20)
- if newUrl == "" {
- continue
- }
- courseIdTmp, sectionIdTmp, midTmp := getSectionIdFromUrl(newUrl)
- if courseIdTmp == "" || sectionIdTmp == "" || midTmp =="" {
- continue
- }
- //fmt.Printf("courseid:%s, secid:%s, mid:%s,%s\n", courseIdTmp, sectionIdTmp, midTmp, url)
- time.Sleep(1*time.Second)
- vedioComplete(wd, midTmp, courseIdTmp, sectionIdTmp)
- //vedioComplete(wd, mid.Id, courseId, sec)
- //if strings.Contains(mid.Name, "充分认识新发展阶段就是聚焦高质量发展的阶段") {
- //time.Sleep(1000*time.Second)
- //}
- fmt.Printf("%s 视频处理完成\n", mid.Name)
- //time.Sleep(1000*time.Second)
- }
- }
- return nil
- }
|