Basically, I want to send the content of a variable to my computer to use it in a Python (Selenium) software. Can I achieve this using an HTTP service, or is there another way? Looking for insights and alternative solutions.
Yes, you can use HTTPService, but it has to be on the server, not the client. I’ve done something similar, and I’d recommend using flask to achieve this. This way you can just hit your own HTTP endpoint, and call the selenium function using flask routes. If you need the data on the client, just send it through remotes. Keep in mind that you’ll need to port forward to have it actually work in games, but in roblox studio you can just route to localhost:8080
(or whatever flask is set to host on).
Alternatively you could try to scrape the API of the website you’re looking to get data from, if possible. In that case you wouldn’t even need a webserver, and it would simplify everything significantly.
According to the docs…
Plugins may also communicate with other software running on the same computer through the localhost and 127.0.0.1 hosts. By running programs compatible with such plugins, you can extend the functionality of your plugin beyond the normal capabilities of Roblox Studio, such as interacting with your computer’s file system. Beware that such software must be distributed separately from the plugin itself, and can pose security hazards if you aren’t careful.
As for other solutions, you could have a server monitor POST requests sent. Roblox Lua has support for POST requests:
-- Example from the docs...
local HttpService = game:GetService("HttpService")
local URL_PASTEBIN_NEW_PASTE = "https://pastebin.com/api/api_post.php"
local dataFields = {
-- Pastebin API developer key from
-- https://pastebin.com/api#1
["api_dev_key"] = "FILL THIS WITH YOUR API DEVELOPER KEY",
["api_option"] = "paste", -- keep as "paste"
["api_paste_name"] = "HttpService:PostAsync", -- paste name
["api_paste_code"] = "Hello, world", -- paste content
["api_paste_format"] = "text", -- paste format
["api_paste_expire_date"] = "10M", -- expire date
["api_paste_private"] = "0", -- 0=public, 1=unlisted, 2=private
["api_user_key"] = "", -- user key, if blank post as guest
}
-- The pastebin API uses a URL encoded string for post data
-- Other APIs might use JSON, XML or some other format
local data = ""
for k, v in pairs(dataFields) do
data = data .. ("&%s=%s"):format(HttpService:UrlEncode(k), HttpService:UrlEncode(v))
end
data = data:sub(2) -- Remove the first &
-- Here's the data we're sending
print(data)
-- Make the request
local response = HttpService:PostAsync(URL_PASTEBIN_NEW_PASTE, data, Enum.HttpContentType.ApplicationUrlEncoded, false)
-- The response will be the URL to the new paste (or an error string if something was wrong)
print(response)
The above example sends a request to Pastebin’s API to create a new paste.
EDIT: I should mention that a lot of APIs use JSON for data rather than query parameters. If you’re using Flask (it’ll need to be port forwarded), it has support for query parameters:
from flask import request
@app.route('/thing')
def data():
# blah will be equal to whatever comes after ?blah= in the address bar.
blah = request.args.get('blah')
Alternatively you could try to scrape the API of the website you’re looking to get data from, if possible. In that case you wouldn’t even need a webserver, and it would simplify everything significantly.
Wdym? I’m trying to send the value of a variable to the software, the value will be given by a player using a text box
You’re saying that you intend on using Selenium, which is often used as a workaround on websites that don’t provide an openly documented API. I’m suggesting that, if possible, just spoof the raw API request provided by whatever server you’re gathering data from, which can be done directly from Roblox and wouldn’t require a server.
Of course, this isn’t always possible, and it’s usefulness depends on what you’re actually doing.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.