Scrape a webpage and get element by id, or store info in an array?

Are either options possible?

Im a mod for someone who streams old school runescape content.
Sometimes he’ll say “Do you guys remember which monsters spawn on this wave?”

Well the waves hes referring to, there’s 69 total.
Rather than create 69 commands like !wave1 !wave2 etc, I want to create one function that stores information for all 69 waves.

Maybe theres a better way to do this. I’m new to nightbot and I’m not really a programmer I just know basic concepts, so this is the first thing I thought of.

I have a domain name so I was going to just post line by line what each wave is on my website somewhere in their own div id, then use nightbot to scrape it. Something like

!wave1 = webscrapefunction(domainname, getelementbyid(‘wave1’)

Is something like this possible? Or can I just store each wave information locally in an array and do !wave $(num) = waves[$(num)]

Waves[0] would look like

3x Nibbler, 1x Bat

*I just saw $(eval) on the docs. Can I pass through $(num) to $(eval)? I think that’ll be my best bet if I can.

So right now I’m trying

$(number) $(eval wavelist = [0,1,2,3]; wavelist[$(number)]) but getting invalid variable.

Also tried $(number) $(eval wavelist = [0,1,2,3]; wavelist[\$(number)]) but getting invalid variable.

*Okay I figured it out, but it seems like nightbot has a character limit and I cant fit the whole array (2500 characters.) Cant url fetch either since that supports 400 characters.

*Ayo I got it working.

$(eval var $(urlfetch json mywebsite.com/waves); wavelist[$(1)];)

2 Likes

You could edit your site just pass a query using $(query) such as $(urlfetch website.com/stats?q=$(query)) and have the website return just the the plaintext output of the given wave.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.