2013-02-08 29 views
5

我正在嘗試使用編程語言搜索谷歌或另一個指定的搜索引擎。我想使用windows cmd提示符來執行此操作,因爲指定的編程語言具有訪問cmd提示符的簡單命令。使用cmd提示搜索谷歌或其他搜索引擎上的字

關於如何從cmd提示搜索谷歌的任何想法?

+0

您是否僅使用命令提示符進行設置?如果是,那麼在命令提示符下沒有工具可以讓你這樣做。最好的辦法是ping www.google.com,但不能使用命令提示符代替Web瀏覽器。現在,如果你打算說可能是PowerShell,那麼這是一個不同的故事。 – TimWagaman 2013-02-08 17:50:52

+0

好的。我將研究PowerShell。你如何在PowerShell中做到這一點?我對PowerShell很不熟悉。 – 2013-02-08 17:57:11

+0

@ R_USER82在powershell中可以使用[psgoogle](https://www.powershellgallery.com/packages/PsGoogle) – gordy 2016-02-02 19:05:04

回答

0

我想你可以在命令行中使用wget

wget -U "Firefox/3.0.15" http://www.google.com/search?q=SEARCH+TERMS+HERE -O result.html -q 

-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" 

...獲取谷歌搜索的第一個鏈接的網址。天空是極限。獲得創意。

(上面的例子命令的輸出: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 
) 

用法: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> 
3

只需在命令行或在運行命令鍵入這一點,它會打開你的默認瀏覽器,讓谷歌搜索SEARCHTERM

start www.google.com/search?q=SEARCHTERM 

請注意,您必須更換空格帶有加號,例如

start www.google.com/search?q=Use+cmd+prompt+to+search+a+word+on+google+or+other+search+engine 

另外,您也可以在批處理文件中把這個命令:

@start www.google.com/search?q=%1+%2+%3+%4+%5+%6+%7+%8+%9 
1

我創建了一個批處理文件「g.bat」,並把它添加到我的道路。它看起來像這樣:

start www.google.co.uk/search?q=%1+%2+%3+%4+%5 

支持最多5個單詞(當然,您可以添加更多)。現在我可以從CMD搜索或通過鍵入「G查詢」

編輯開始:感謝地鐵爲靈感

-1
  • 打開記事本文件
  • start www.google.com/
  • 保存的文件。蝙蝠extensionthen
  • 打開批處理文件每次打開谷歌搜索
  • 沒有必要去命令提示符每次
+0

這並不能解決用戶的需求。嗨想搜索一個詞,不僅打開谷歌。 – jruizaranguren 2014-11-07 10:40:20

1

您可以在PS1文件寫:

function googleSearch{start www.google.com/search?q=$args} 
set-alias g googleSearch 

然後重新啓動powershell,

g whatwhatwhat 
-1

也許這樣?

@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 

保存爲.BAT 和繁榮!

0

容易。

@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 
0

如果妳使用的是Java那麼該死的容易...

// Java程序來說明在命令提示符

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(); 
     } 
    } 
} 

希望 //執行命令這工作!榮譽。

相關問題