Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. url := "https://www.lynda.com/allcourses/"
  2. output := A_ScriptDir . "\cources.txt"
  3.  
  4. html := GetHtml(url) ; this may take time
  5. cources := GetCources(html)
  6. SaveToFile(output, cources)
  7. Run, % output
  8.  
  9. GetHtml(url) {
  10.    oWhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  11.    oWhr.SetTimeouts(0, 120000, 120000, 120000)
  12.    oWhr.Open("GET", url, true)
  13.    oWhr.Send()
  14.    oWhr.WaitForResponse()
  15.    Return html := oWhr.ResponseText
  16. }
  17.  
  18. GetCources(html) {
  19.    doc := ComObjCreate("htmlfile")
  20.    doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
  21.    doc.write(html)
  22.    courceContainer := doc.querySelector("ul.course-list")
  23.    items := courceContainer.getElementsByTagName("h3")
  24.    Loop % items.length {
  25.       item := items[A_Index - 1]
  26.       itemText := item.innerText
  27.       itemLink := item.getElementsByTagName("a")[0].getAttribute("href")
  28.       text .= (text ? "`r`n`r`n" : "") . "Title: " . itemText . "`r`nLink:  " . itemLink
  29.    }
  30.    Return text
  31. }
  32.  
  33. SaveToFile(filePath, string) {
  34.    oFile := FileOpen(filePath, "w")
  35.    oFile.Write(string)
  36.    oFile.Close()
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement