使用cmd提示符搜索谷歌或其他搜索引擎上的单词

Par*_*eto 5 windows console search cmd

我正在尝试使用编程语言来搜索谷歌或其他指定的搜索引擎.我想使用windows cmd提示符这样做,因为指定的编程语言有一个简单的命令来访问cmd提示符.

有关如何从cmd提示搜索谷歌的任何想法?

And*_*eas 7

只需在命令行或运行命令中键入此内容,它就会打开您的默认浏览器让 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)


roj*_*ojo 0

我想你可以从命令行使用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)