scope googleImageSearch_new2. static S #userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"; static int #timeout = 10*1000; static new ThreadLocal #nsfw; static BufferedImage googleImageSearch_new2(S q) { S html = loadPage_cached(q); S group = regexpFirstGroup("image/jpeg;base64,([a-zA-Z0-9/+]*)={0,2}", html); ret group == null ? null : imageFromBytes(base64decode(dropLast(l(group) & 3, group))); } sS #loadPage_cached(S q) { File f = googleImageSearch_htmlCacheFile(q); if (fileSize(f) > 0) ret loadTextFile(f); S html = loadPage(q); saveTextFile(f, html); ret html; } sS #loadPage(S q) ctex { S googleUrl = "https://www.google.com/search?tbm=isch" + (!isTrue(nsfw!) ? "&safe=active" : "") + "&q=" + urlencode(q); print("Googling " + quote(q)); ret loadPageWithUserAgentAndTimeout(googleUrl, userAgent, timeout); } end scope