Code Golf : Parsing google results
Bash + grep + lynx, 38
Since we can open a web browser, then I will use lynx
:
lynx -dump $1|grep -Po '(?<=d:)[^&]+'
(Thanks to @manatwork for grep
usage instead of sed
)
We pass in the whole URL in as a parameter:
$ ./gr.sh "www.google.com/search?q=stackexchange&ie=utf-8&oe=utf-8"
http://stackexchange.com/
https://en.wikipedia.org/wiki/Stack_Exchange
https://twitter.com/stackexchange
https://play.google.com/store/apps/details?id=com.stackexchange.marvin
https://github.com/StackExchange/StackExchange.Redis
https://github.com/StackExchange/StackExchange.Redis/blob/master/Docs/Basics.md
https://www.crunchbase.com/organization/stack-exchange
$
Which gives the same list as:
Ruby, 91 77 bytes
require'open-uri';open(gets).read.scan(/ed:(.*?)\+/){|x|puts URI.decode x[0]}
Would've been shorter without all the EDIT: So, turns out, I don't need the second require! Thanks to @manatwork for pointing that out.require
s. ARGH!!!
Older version (with the useless require
):
require'open-uri';require 'uri';open(gets).read.scan(/ed:(.*?)\+/){|x|puts URI.decode x[0]}
Wolfram Language (Mathematica), 135
StringJoin/@(Cases[URLExecute["www.google.com/search",{"q"->#},"XMLObject"],XMLElement["cite",_,l_]:>l,-1]/.XMLElement["b",_,{s_}]:>s)&
more readable:
StringJoin/@(Cases[
URLExecute["www.google.com/search",{"q"->#},"XMLObject"],
XMLElement["cite",_,l_]:>l,-1] /.
XMLElement["b",_,{s_}]:>s)