Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Using gmatch with returned GetAsync?

Asked by 8 years ago

I'm making a stock updater in ROBLOX for my own purposes, and so I found a website that lists all the stock symbols and names. Before each stock symbol, it is followed by the string in the tomatch variable. The string I'm trying to match is repeated many times in each website, right before a stock symbol (ex: AAPL). Every time I run it, it returns 0 stocks found. I made sure that the page type was a string, so I don't get why it's not finding that string repeated multiple times. Can you help me?

local http = game.HttpService;
matches = {};
tomatch = '<TD VALIGN=TOP ALIGN=LEFT WIDTH=124><P ALIGN=LEFT><FONT COLOR="#000000" SIZE="-1" FACE="MS Sans Serif">'
url = "http://www.allstocks.com/NASDAQ/nasdaq_stock_symbols_a.html";
page = http:GetAsync(url, true);
for val in string.gmatch(page, tomatch) do
    table.insert(matches, val);
end;

print(type (page))
print()
print("Number of different stocks found: " .. #matches)

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

There are two problems with tomatch that I can see.

  1. There isn't any row with WIDTH=124 on the page. If you want to match any width, you should use a pattern like WIDTH=%d+ to mean any sequence of at least one digit.

  2. - is a pattern, so you have to escape it as %-.

You'll then get every table row.

Since this website doesn't change, it doesn't really make sense to use HTTP service to do this. Just copy the table into excel and copy out the column you need, and move it into a module script as simpler text (e.g., just newline separated)

Ad

Answer this question