Parse HTML to get list of usernames?

I’m at a loss. I was going to use CURL but I couldn’t login, i tried -u username:password but that didnt work. So i resorted to using safari, loading the page and grabbing the body of the page with


tell application "Safari"
	
	set theSource to do JavaScript "document.body.innerHTML" in tab 1 of window 1
	
end tell

I need now to parse the html and create a list of all the usernames on that page and put them in a list for further processing.

Each username is surrounded by the following html tags:

USERNAME

Can anyone point me in the right direction, please?

You don’t give a sample, but for the line you do give, this works. If there are many, then you will need some loops.


set html to "<td class=\"username\">USERNAME</td>"
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ">"
set part_1 to text item 2 of html
set AppleScript's text item delimiters to "<"
set UName to text item 1 of part_1 --> "USERNAME"
set AppleScript's text item delimiters to tid

Thank you thank you! This works great on my computer… But I ended up going the UserScript route and making something all of the mods on my team can use and not just me.