windows 使用 cmd prompt 在谷歌或其他搜索引擎上搜索一个词
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14778318/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use cmd prompt to search a word on google or other search engine
提问by Pareto
I am trying to use a programming language to searchgoogle or another specified search engine. I would like to use windows cmd prompt to do so because the specified programming language has a simple command to access the cmd prompt.
我正在尝试使用一种编程语言来搜索google 或其他指定的搜索引擎。我想使用 windows cmd 提示符来这样做,因为指定的编程语言有一个简单的命令来访问 cmd 提示符。
Any ideas on how to search google from cmd prompt?
关于如何从 cmd 提示符搜索谷歌的任何想法?
回答by Andreas
Simply type this on the command-line or in the run command and it will open your default browser to let Google search for SEARCHTERM
:
只需在命令行或运行命令中键入此内容,它就会打开您的默认浏览器让 Google 搜索SEARCHTERM
:
start www.google.com/search?q=SEARCHTERM
Note that you have to replace whitespaces with pluses, e.g.
请注意,您必须用加号替换空格,例如
start www.google.com/search?q=Use+cmd+prompt+to+search+a+word+on+google+or+other+search+engine
Alternatively you could also put this command in a batch file:
或者,您也可以将此命令放在批处理文件中:
@start www.google.com/search?q=%1+%2+%3+%4+%5+%6+%7+%8+%9
回答by tompattman
I created a Batch file 'g.bat' and added it to my PATH. It looks like this:
我创建了一个批处理文件“g.bat”并将其添加到我的路径中。它看起来像这样:
start www.google.co.uk/search?q=%1+%2+%3+%4+%5
Supports up to 5 words (of course you can add more). Now I can search from CMD or start by typing "g query"
最多支持 5 个单词(当然您可以添加更多)。现在我可以从 CMD 搜索或输入“g query”开始
Edit: Credit to mrt for the inspiration
编辑:归功于 mrt 的灵感
回答by tab
You can write in the ps1 file:
可以在ps1文件中写入:
function googleSearch{start www.google.com/search?q=$args}
set-alias g googleSearch
then restart your powershell,
然后重启你的powershell,
g whatwhatwhat
回答by Jonathan Pettersson
easy.
简单。
@echo off
color a
setlocal ENABLEDELAYEDEXPANSION
echo Google Batch
echo Made By GenoSans
start https://discord.gg/WwRtbBe
timeout -t 5 /nobreak
:a
cls
echo ,,
echo .g8'''bgd `7MM
echo .dP' `M MM
echo dM' ` ,pW'Wq. ,pW'Wq. .P'Ybmmm MM .gP'Ya
echo MM 6W' `Wb 6W' `Wb :MI I8 MM ,M' Yb
echo MM. `7MMF'8M M8 8M M8 WmmmP' MM 8M''''''
echo `Mb. MM YA. ,A9 YA. ,A9 8M MM YM. ,
echo `'bmmmdPY `Ybmd9' `Ybmd9' YMMMMMb .JMML.`Mbmmd'
echo 6' dP
echo Ybmmmd'
echo.
set /p s=Search:
set word=+
set str=%s%
set str=%str: =!word!%
start http://www.google.com/search?q=%str%
goto a
回答by Khushit Shah
If u are using java then it is damn easy...
如果你使用的是java,那么它很容易......
// Java program to illustrate // executing commands on cmd prompt
// Java 程序来说明 // 在 cmd 提示符下执行命令
class NewClass
{
public static void main(String[] args)
{
try
{
Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"start www.google.com/search?q=**search here instead of space use '+'**\"");
}
catch (Exception e)
{
System.out.println("HEY Buddy ! U r Doing Something Wrong ");
e.printStackTrace();
}
}
}
Hope this works! Kudos.
希望这有效!荣誉。
回答by rojo
I suppose you could use wgetfrom the command line.
我想你可以从命令行使用wget。
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.
或者-O- -q
输出到标准输出。不过,从 html 中抓取结果将是完全不同的事情。
If you do get wget, might as well get grepas well, or just get all of GnuWin32as it's quite useful. Then you can do stuff like this:
如果你确实得到了 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"
... to get the URL of the first link from a Google search. The sky's the limit. Get creative.
...从 Google 搜索中获取第一个链接的 URL。天空是极限。发挥创意。
(Output of the example command above: isaksen.biz/blog/?p=470
)
(上面的示例中命令的输出:isaksen.biz/blog/?p=470
)
If you want to display the first title plus the first URL, it gets a little more complicated.
如果你想显示第一个标题加上第一个 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
)
Usage: search.bat up to 9 search terms here
用法: 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>
回答by premz
- open Notepad file
- type
start www.google.com/
- save the file with .bat extensionthen
- open the batch file everytime to open Google search
- no need to go to cmd prompt every time
- 打开记事本文件
- 类型
start www.google.com/
- 用 .bat 扩展名保存文件然后
- 每次打开批处理文件打开谷歌搜索
- 无需每次都进入 cmd 提示符
回答by Matthew
Maybe this?
也许这个?
@echo off
:start
cls
echo.
echo G O O G L E Web Search Version 1.1
echo.
echo Type search terms, and your internet browser will open it.
echo.
set /p Web=
start www.google.com/search?q=%Web%
goto start
Save it as .bat and boom!
将其另存为 .bat 并繁荣!