只需在命令行或运行命令中键入此内容,它就会打开您的默认浏览器让 Google 搜索SEARCHTERM
:
start www.google.com/search?q=SEARCHTERM
Run Code Online (Sandbox Code Playgroud)
请注意,您必须用加号替换空格,例如
start www.google.com/search?q=Use+cmd+prompt+to+search+a+word+on+google+or+other+search+engine
Run Code Online (Sandbox Code Playgroud)
或者,您也可以将此命令放在批处理文件中:
@start www.google.com/search?q=%1+%2+%3+%4+%5+%6+%7+%8+%9
Run Code Online (Sandbox Code Playgroud)
我想你可以从命令行使用wget 。
wget -U "Firefox/3.0.15" http://www.google.com/search?q=SEARCH+TERMS+HERE -O result.html -q
Run Code Online (Sandbox Code Playgroud)
或者-O- -q
输出到标准输出。不过,从 html 中抓取结果将是完全不同的事情。
如果您确实获得了 wget,不妨也获得grep ,或者直接获得GnuWin32 的全部内容,因为它非常有用。然后你可以做这样的事情:
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"
Run Code Online (Sandbox Code Playgroud)
...从 Google 搜索中获取第一个链接的 URL。天空是极限。发挥创意。
(上面示例命令的输出isaksen.biz/blog/?p=470
:)
如果你想显示第一个标题和第一个 URL,那就有点复杂了。
@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
)
Run Code Online (Sandbox Code Playgroud)
用法:search.bat up to 9 search terms here
例子:
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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
19936 次 |
最近记录: |