I'm trying to make a program that asks for the name of a university "e.g., central michigan university"
then scours the first 10 hits of studyblue for cue cards for different classes, and prints those to a folder on my computer.
a screenshot from the site is right here https i.postimg.cc/LX4jSC8r/image.png
the problem i'm having is that i'm trying to look for how many decks of cue cards there are available (highlighted yellow number), and then if it is greater than 0, click the link and go to the course to print them off.
using css selectors, i saw that each course (e.g., Economics 101) has its own selector of the format
Code: Select all
#course-list-items > div:nth-child(#) > span.list-item-option.study-item-metric.span2.offset4
so I was trying to loop through these numbers and get the innertext of the span that contains the highlighted yellow number to know whether to click on it, but I have been getting errors no matter what I try.
Here's my code
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
pwb := ComObjCreate("InternetExplorer.Application")
pwb.visible := true
pwb.toolbar := false
numberlink := 21
num := 1
InputBox query
StringReplace, search, query, %A_Space%, `%20, all
navigate = https www.studyblue.com /#search/classes/%search%/scope=ALL Broken Link for safety
MsgBox % navigate
pwb.navigate(navigate)
while pwb.ReadyState != 4
Sleep, 100
Loop, 10 {
queryselected = "#course-list-items > div:nth-child(%num%) > div > a"
cards = "#shared-content-view > section > div > div > div.document-list > div > div:nth-child(%num%) > span.new-study-item__title.js-title-text > a"
counter = "#course-list-items > div:nth-child(%num%) > span.list-item-option.study-item-metric.span2.offset4"
value = pwb.document.querySelector(%counter%).InnerText
msgbox % queryselected
msgbox % value
if (pwb.document.querySelector(counter).innerText > 0) {
coursename = document.querySelector(queryselected).InnerText
pwb.document.querySelector(queryselected).Click()
while pwb.ReadyState != 4
Sleep, 100
Loop, %value% {
pwb.document.querySelector(cards).Click()
while pwb.ReadyState != 4
Sleep, 100
pwb.document.querySelector("#deck-preview-toolbar__more-icon").Click()
while pwb.ReadyState != 4
Sleep, 100
pwb.document.queryselector("#printDeck > span").Click()
while pwb.ReadyState != 4
Sleep, 100
pwb.document.queryselector("body > div > div.instructions > div > div.steps.steps-02 > div > a").Click()
pwb.visible := true
while pwb.ReadyState != 4
Sleep, 100
Send, {enter}
Send, %query%%num%
Send, ^{l}
Send, ^{a}
tosend = C:\Users\tgrid\OneDrive\Desktop\AHKStudio\Projects\Colleges\%query%
Send, %tosend%
Send, {enter}
Send, {enter}
Send, {enter}
pwb.visible := false
}
}
num := num + 1
pwb.navigate(navigate)
}