Hi! I’m trying to learn http.request, and I thought a fun little exercise would be getting certain text. For example, get the text that says “Inbox” on Codea. Is this possible?
Thanks,
Prynok
Hi! I’m trying to learn http.request, and I thought a fun little exercise would be getting certain text. For example, get the text that says “Inbox” on Codea. Is this possible?
Thanks,
Prynok
Sure http.request is going to return the page source. You can search the returned string and grab what you like. I’m not sure why’d you grab the text inbox but you could.
@Prynok There’s not much code to get “inbox”. But what you do with it might take a lot more.
function setup()
http.request("http://twolivesleft.com/Codea/Talk/messages/inbox",gotData,fail)
end
function draw()
background(40, 40, 50)
end
function fail(error)
print(error)
end
function gotData(data,status,headers)
print(data)
print(status)
for x,y in pairs(headers) do
print(x,y)
end
end
@dave1707, Thanks, but I already know how to do that. I was asking how to get certain text from the data, and I used the text “Inbox” at the top of the screen as a example.
@Prynok Sorry, I didn’t understand the exact question. To get any text, a string.find, string.match, etc, would be used to find what you’re after in the data, or header information that you get back. But then you probably know how to use those also.
string.gsub if you plan to replace it with another piece of text
@Prynok - Codea will return the HTML web page. To see what this looks like, load the page in your web browser and view the source (eg in Firefox, look under Tools, Web developer, Page source).
Find what you want there, and figure out what unique text tags you can use to locate it with a text search when it is downloaded. Then use string.find and string.sub to extract it.
No shortcuts, I’m afraid… Every page is different.