Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

33
LINES

< > BotCompany Repo | #1005225 // pouetOneLiners

JavaX fragment (include)

sclass OneLiner {
  S userName;
  S contents; // html
}

// get the 5 one-liners from home page
static L<OneLiner> pouetOneLiners() {
  ret pouetOneLiners(loadPageWithUserAgent("http://pouet.net", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0"));
}

static L<OneLiner> pouetOneLiners(S html) {
  new L<OneLiner> out;
  L<S> tok = htmlTok(html);

  int i = tok.indexOf("<div class='pouettbl' id='pouetbox_latestoneliner'>");
  if (i >= 0) {
    int j = findEndOfContainerTag(tok, i);
    if (j >= 0) {
      L<S> tok2 = subList(tok, i+1, j-1);
      //psl(tok2);
      L<L<S>> l = unwrapContainerTags(findContainerTag(tok2, "li"));
      for (L<S> tok3 : l) pcall {
        psl(tok3);
        int k = indexOf(tok3, "</a>");
        new OneLiner o;
        o.userName = getHtmlTagParameter(tok3.get(1), "title");
        o.contents = trim(join(subList(tok3, k+1)));
        out.add(o);
      }
    }
  }
  ret out;
}

Author comment

Began life as a copy of #1005219

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005225
Snippet name: pouetOneLiners
Eternal ID of this version: #1005225/2
Text MD5: dbf8782702acf2e528c111958122f5d8
Author: stefan
Category: javax / web scraping
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-15 15:49:27
Source code size: 978 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 608 / 565
Version history: 1 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)