Jump to content




String:gsub Help


  • You cannot reply to this topic
1 reply to this topic

#1 johnnic

  • Members
  • 50 posts
  • LocationSomewhere in ****** County, *******

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.

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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)






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users