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

30
LINES

< > BotCompany Repo | #1002511 // Scraping Google Image Search Bot (LIVE)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 616K of libraries. Click here for Pure Java version (2367L/18K/56K).

!7
lib 1002510 // jsoup

import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

static S userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";

answer {
  if (matchStart("show", s, m)) exceptionToUser {
    S query = m.rest().trim();
    if (nempty(query))
      ret findImage(query);
  }
}

public static String findImage(String question) ctex {
  ret urlShortener(findImageNoShorten(question));
}

public static String findImageNoShorten(String question) ctex {
  String googleUrl = "https://www.google.com/search?tbm=isch&q=" + urlencode(question);
  Document doc1 = Jsoup.connect(googleUrl).userAgent(userAgent).timeout(10 * 1000).get();
  Element media = doc1.select("[data-src]").first();
  String finUrl = media.attr("abs:data-src"); 

  ret htmldecode(finUrl);
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002511
Snippet name: Scraping Google Image Search Bot (LIVE)
Eternal ID of this version: #1002511/2
Text MD5: 8fdd795ae56fbc3056a23fc9bf8933e1
Transpilation MD5: 432d653efd3d2fe6a78b81a82844f1fc
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-04 00:51:21
Source code size: 890 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 701 / 1407
Version history: 1 change(s)
Referenced in: #1002861 - AI Management Bot
#1003348 - Test Google Video Search (hm. needs new parsing)
#1004999 - googleImageSearch
#3000185 - Answer for stefanreich
#3000188 - Answer for stefanreich(>> t search)
#3000190 - Answer for stefanreich(>> t 20 questions)
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000203 - Answer for stefanreich (>> timing hello bot)
#3000208 - Answer for bgrgndz (>> list sub bots)
#3000209 - Answer for bgrgndz (>> list sub bots)
#3000238 - Answer for stefanreich (>> t power bot)
#3000369 - Answer for Stefan (>> list sub bots)
#3000376 - Answer for stefanreich (>> list sub bots)
#3000378 - Answer for stefanreich (>> show file "1002967/inToOut")
#3000380 - Answer for stefanreich (>> list sub bots)
#3000381 - Answer for speedforce (>> list sub bots)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)