This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
johnnic's profile picture

String:gsub Help

Started by johnnic, 06 November 2013 - 07:28 PM
johnnic #1
Posted 06 November 2013 - 08:28 PM
Hello. I am trying to read an html page and then get an authenticity token. However, i get the error:
bad argument: string\table\function expected.
Is there something I am doing wrong?

e=e:gsub("<form action=\"/session\" id=\"login_form\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"authenticity_token\" type=\"hidden\" value=\"")
Thanks in advance.
Bomb Bloke #2
Posted 07 November 2013 - 02:52 AM
You've specified a "pattern" to look for in your "e" string, but you've not specified what you want to do when it's found. I'm not certain gsub is suited to your purpose - normally you'd attempt to replace the matching text or run a function based on it (Lua is wondering what to replace with, or run). I suggest taking a closer look at this string tutorial.

I've not tried it via ComputerCraft (just repl.it), but this sort of code may be somewhat more suitable:

e="<form action=\"/session\" id=\"login_form\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"authenticity_token\" type=\"hidden\" value=\"cabbagecabbagecabbage\">"

c,d,e = e:find("value=\"(.*)\">")

print(e)