Jump to content
  • 0

How to load a variable from http?


slaimmials

Question

4 answers to this question

Recommended Posts

Hi @slaimmials, What "load variable" means here? Kinda confused with the way you wording the sentence. Is it Variable that parts of Online Script? or Variable here means String? 
[ Online Script ]
Let's say you're trying to get 'Variable', which is inside a script, isn't it? You must change the literal Variable into returning values inside the Online Script.

variable = 'abogoboga' -- x: wrong
return 'abogoboga' -- v: correct

then you can do some Request into the HTTP Site:

http_content = gg.makeRequest(link).content
load_content = load(http_content)()

[ Webscrape ]
Another thing is to get literal String from HTTP Site, which is part of Webscraping. If the HTTP Site content is RAW (no HTML, attachment or attributes) then you can just do usual Request:

--Taking content from RAW Pastes or Github
github_content = gg.makeRequest('https://raw.githubusercontent.com/gilts/wsee/main/.wsee/CONFIG')
print(github_content)

Most websites has HTML to define the web structure, thus you need to parse it manually. LUA isn't really powerfull for this kind of stuff but it is still sufficient using in-built tools:

  • - :gmatch: Return Matches and Iterate the Result.
  • - :match: Return Captures from the first Match.
  • - :find: Return First Match and Position.
  • - :gsub: Subtitutes / Replacement for Matches

For example, we want to get the IP address from the following website: hostmap

web_content = gg.makeRequest('https://suip.biz/?act=hostmap').content --Returns HTML
for i in web_content:gmatch('([^;">]+)</li>') do --Parse HTML: Find Matches
	for i in i:gsub("[%c%s]",""):gmatch('%d+%.%d+%.%d+%.%d+') do --Parse HTML: Matches IP Pattern
		print(i) --Print Result
	end
end

Read more about this: LUA Capture and makeRequest

Link to comment
Share on other sites

8 hours ago, MC189 said:

Hi @slaimmials, What "load variable" means here? Kinda confused with the way you wording the sentence. Is it Variable that parts of Online Script? or Variable here means String? 
[ Online Script ]
Let's say you're trying to get 'Variable', which is inside a script, isn't it? You must change the literal Variable into returning values inside the Online Script.

variable = 'abogoboga' -- x: wrong
return 'abogoboga' -- v: correct

then you can do some Request into the HTTP Site:

http_content = gg.makeRequest(link).content
load_content = load(http_content)()

[ Webscrape ]
Another thing is to get literal String from HTTP Site, which is part of Webscraping. If the HTTP Site content is RAW (no HTML, attachment or attributes) then you can just do usual Request:

--Taking content from RAW Pastes or Github
github_content = gg.makeRequest('https://raw.githubusercontent.com/gilts/wsee/main/.wsee/CONFIG')
print(github_content)

Most websites has HTML to define the web structure, thus you need to parse it manually. LUA isn't really powerfull for this kind of stuff but it is still sufficient using in-built tools:

  • - :gmatch: Return Matches and Iterate the Result.
  • - :match: Return Captures from the first Match.
  • - :find: Return First Match and Position.
  • - :gsub: Subtitutes / Replacement for Matches

For example, we want to get the IP address from the following website: hostmap

web_content = gg.makeRequest('https://suip.biz/?act=hostmap').content --Returns HTML
for i in web_content:gmatch('([^;">]+)</li>') do --Parse HTML: Find Matches
	for i in i:gsub("[%c%s]",""):gmatch('%d+%.%d+%.%d+%.%d+') do --Parse HTML: Matches IP Pattern
		print(i) --Print Result
	end
end

Read more about this: LUA Capture and makeRequest

thx

Link to comment
Share on other sites

some_text = [[
print('text have been loaded')
]]

result,err = pcall(load(some_text,'t')) -- t as 2ed parameter to load will load string same as loadstring()

result,err = pcall(load(some_text,'b')) -- assume that some_text is a binary code ( compiled ) the 'b' will load it as binary

result,err = pcall(load(some_text,'bt')) -- bt will load it either it's a text or a binary

if result then result() end -- add () to execute the code
-- if it's a value use tostring / tonumber to modify the type of this variable to prevent error

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.