Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


edited December 2013 in General Posts: 577

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?




  • BriarfoxBriarfox Mod
    Posts: 1,542

    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.

  • dave1707dave1707 Mod
    Posts: 9,817

    @Prynok There's not much code to get "inbox". But what you do with it might take a lot more.

    function setup()     http.request("",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
  • Posts: 577

    @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. :)

  • dave1707dave1707 Mod
    edited December 2013 Posts: 9,817

    @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

  • IgnatzIgnatz Mod
    Posts: 5,396

    @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.

  • Posts: 577

    @Ignatz Thanks!

  • Posts: 1,976

    @Ignatz Rather than getting the exact position, you could also do string matching to maybe iterate through say, every


    p> tag and extract the text from it.

    @Prynok Tutorial-like comment on string matching here.

Sign In or Register to comment.