プログラミング言語を使用して、Google または別の指定された検索エンジンを検索しようとしています。指定されたプログラミング言語には cmd プロンプトにアクセスするための簡単なコマンドがあるため、Windows cmd プロンプトを使用して実行したいと考えています。
コマンドプロンプトからGoogleを検索する方法についてのアイデアはありますか?
これをコマンドラインまたは実行コマンドに入力するだけで、デフォルトのブラウザーが開き、Google が検索できるようになります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
ps1 ファイルに次のように記述できます。
function googleSearch{start www.google.com/search?q=$args}
set-alias g googleSearch
次に、PowerShell を再起動します。
g whatwhatwhat
コマンドラインから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"
... 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
)
使用法: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>
もしかしてこれ?
@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 とブームとして保存します。
start www.google.com/