static L<Pair<S>> quickGoogle(S query) { new L<Pair<S>> out; S userAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0"; S html = loadPageWithUserAgent("http://google.com/search?q=" + urlencode(query) + "&lr=lang_en&hl=en", userAgent); S url = first(loadPage_responseHeaders->get("Location")); if (url != null) html = loadPageWithUserAgent(url, userAgent); LL<S> h3s = findContainerTagDeep(html, "h3"); for (L<S> tok : h3s) { L<S> linkTok = first(findContainerTag(tok, "a")); if (empty(linkTok)) continue; S link = tagGet(second(linkTok), "href"); continue unless isAbsoluteURL(link); S text = htmldecode(join(dropTags(contentsOfContainerTag(linkTok)))); out.add(pair(link, text)); } ret out; }
Began life as a copy of #1011236
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1011241 |
Snippet name: | quickGoogle - returns pairs of (link, text) |
Eternal ID of this version: | #1011241/4 |
Text MD5: | 04086e6adb61b4a7974a69cc157d216f |
Author: | stefan |
Category: | javax / networking |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-11-14 09:32:13 |
Source code size: | 812 bytes / 22 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 512 / 527 |
Version history: | 3 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1011993 - quickGoogle2 - returns triples of (link, text, desc) |