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

17
LINES

< > TinyBrain | #1007251 - googleImageSearchFirst - get first inlined image

JavaX fragment (include)

static BufferedImage googleImageSearchFirst(S q) {
  S html = str(googleImageSearch_loadPage(q));
  S id = regexpFirstGroup("\"id\":\"(..............):\"", html);
  if (id == null) null;
  print("Image search: ID=" + id);
  S s = regexpFirstGroup("\\[\"" + id + ":\",\"data:image/(?:png|jpeg|gif);base64,([^\"]+)", html);
  if (s == null) {
    print("Image search: ID not found. Saving debug");
    saveTextFile(prepareProgramFile(#1007145, "debug.html"), html);
    null;
  }
  try {
    ret decodeImage(base64decode(unquote("\"" + s + "\"")));
  } on fail {
    print("Tried to decode: " + quote(s));
  }
}

download  show line numbers  debug dex   

Travelled to 1 computer(s): tvejysmllsmz

No comments. add comment

Snippet ID: #1007251
Snippet name: googleImageSearchFirst - get first inlined image
Eternal ID of this version: #1007251/10
Text MD5: 77e9bdbe75440a673bb119e6da9adf08
Author: stefan
Category: javax / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-18 14:17:54
Source code size: 625 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 24 / 3
Version history: 9 change(s)
Referenced in: [show]