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

1  
!7
2  
lib 1002510 // jsoup
3  
4  
import org.jsoup.*;
5  
import org.jsoup.nodes.*;
6  
import org.jsoup.nodes.Document;
7  
import org.jsoup.nodes.Element;
8  
9  
static S userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";
10  
11  
answer {
12  
  if (matchStart("show", s, m)) exceptionToUser {
13  
    S query = m.rest().trim();
14  
    if (nempty(query))
15  
      ret findImage(query);
16  
  }
17  
}
18  
19  
public static String findImage(String question) ctex {
20  
  ret urlShortener(findImageNoShorten(question));
21  
}
22  
23  
public static String findImageNoShorten(String question) ctex {
24  
  String googleUrl = "https://www.google.com/search?tbm=isch&q=" + urlencode(question);
25  
  Document doc1 = Jsoup.connect(googleUrl).userAgent(userAgent).timeout(10 * 1000).get();
26  
  Element media = doc1.select("[data-src]").first();
27  
  String finUrl = media.attr("abs:data-src"); 
28  
29  
  ret htmldecode(finUrl);
30  
}

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: 769 / 1496
Version history: 1 change(s)
Referenced in: [show references]