I suppose you could use wget from the command line.
wget -U "Firefox/3.0.15" http://www.google.com/search?q=SEARCH+TERMS+HERE -O result.html -q
Or -O- -q
to output to stdout. Scraping the results from the html will be a different matter entirely, though.
If you do get wget, might as well get grep as well, or just get all of GnuWin32 as it's quite useful. Then you can do stuff like this:
wget -U "Firefox/3.0.15" "http://www.google.com/search?q=wget+google+search" -O- -q 2>&1 | grep -E -o -e "<cite>[^<]+</cite>" | sed -r -e "s/<[^>]+>//g"
... to get the URL of the first link from a Google search. The sky's the limit. Get creative.
(Output of the example command above: isaksen.biz/blog/?p=470
)
If you want to display the first title plus the first URL, it gets a little more complicated.
@echo off
setlocal enabledelayedexpansion
set search=%1 %2 %3 %4 %5 %6 %7 %8 %9
for /l %%a in (1,1,8) do if "!search:~-1!"==" " set search=!search:~0,-1!
set search=%search: =+%
wget -U "Firefox/3.0.15" "http://www.google.com/search?q=%search%" -O search.html -q 2>NUL
for /f "tokens=*" %%I in ('grep -P -o "<h3 class=.*?</h3>" search.html ^| sed -r -e "s/<[^>]+>//g"') do (
echo %%I
goto next
)
:next
set /p I="http://"<NUL
for /f "tokens=*" %%I in ('grep -E -o -e "<cite>[^<]+</cite>" search.html ^| sed -r -e "s/<[^>]+>//g"') do (
echo %%I
del /q search.html
goto :EOF
)
Usage: search.bat up to 9 search terms here
Example:
C:\Users\me\Desktop>search command line google
googlecl - Command line tools for the Google Data APIs - Google ...
http://goosh.org/
C:\Users\me\Desktop>