The item: HTML Module [v2 in the making!] - Roblox
I’ve made a module today, that replicated js DOM functions as lua methods:
- module:getElementsByClassName()
- module:getElementById()
- module:getElementsByTagName()
They are used with html pages. If you want to get a certain data off a website page, but cannot easily access or cannot access apis or JSON like twitter for example, you can use this.
How to use:
- Get the html content of the page with httpaccess (httprequests turned on)
- Get the precise data you were looking for, with the module I created.
Example:
--httprequests turned on.
local http = game:GetService'HttpService';
local url = 'https://www.twitter.com/Roblox';
local x = require(workspace["HTML Module"]);
local data = http:GetAsync(url);
if data~=nil then
local requestedClass = 'TweetTextSize TweetTextSize--normal js-tweet-text tweet-text' --html class of a tweet, found with inspect element
local tweets = x:getElementsByClassName(data, requestedClass, 3)--third parameter is 3, because I don't want my table to be longer than 3 rows.
for i,v in pairs(tweets) do
print(i..': '..v);
end
end
Result:
As stated inside the ‘read me’ part, the scripts should work most of the time, but it is not guaranteed it’ll always work due to the fact that it’s simple string manipulation, and in some cases, html can be really confusing for example, when there are lots of same ‘tags’ inside other tags.
Don’t hesitate to correct me, as string manipulation is not my strong point in lua. I might have used in-built functions in a wrong way, or forgot using a more efficient one.
Feel free to use the module, would be kind if you credited me.
Also I’m not responsible of what you’re doing with my ‘creation’.
Many features off this could be done. For example an in-game twitter feed UI.