Use cmd prompt to search a word on google or other

2019-04-09 02:32发布

I am trying to use a programming language to search google 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.

Any ideas on how to search google from cmd prompt?

8条回答
趁早两清
2楼-- · 2019-04-09 02:48

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:

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
查看更多
混吃等死
3楼-- · 2019-04-09 02:52
  • 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
查看更多
太酷不给撩
4楼-- · 2019-04-09 02:55

If u are using java then it is damn easy...

// Java program to illustrate // executing commands on cmd prompt

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.

查看更多
叼着烟拽天下
5楼-- · 2019-04-09 02:58

I created a Batch file 'g.bat' and added it to my PATH. It looks like this:

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"

Edit: Credit to mrt for the inspiration

查看更多
Luminary・发光体
6楼-- · 2019-04-09 03:02

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>
查看更多
我命由我不由天
7楼-- · 2019-04-09 03:02

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!

查看更多
登录 后发表回答