2016-09-20 7 views
3

バッチファイルを使用してWebサイトからHTMLを取得するために見つかったバッチとJavaの結合スクリプトを使用していますが、URLを使用したときに表示されるとおり、ファイアフォックス。スクリプトが正しくURLを受け取っていない

私はHTMLを引っ張るために使用していたスクリプトは次のとおりです。

@if (@[email protected]) @then 
@echo off 
rem **** batch zone  ********************************************************* 

setlocal enableextensions disabledelayedexpansion 

rem Batch file will delegate all the work to the script engine 
if not "%~1"=="" (
    cscript //E:JScript "%~dpnx0" %1 
) 

rem End of batch area. Ensure batch ends execution before reaching 
rem javascript zone 
exit /b 

@end 
// **** Javascript zone  ***************************************************** 

// Instantiate the needed component to make url queries 
var http = WScript.CreateObject('MSXML2.ServerXMLHTTP.6.0'); 

// Retrieve the url parameter 
var url = WScript.Arguments.Item(0) 

// Make the request 

http.open("GET", url, false); 
http.send(); 

// If we get a OK from server (status 200), echo data to console 

if (http.status === 200) WScript.StdOut.Write(http.responseText); 

// All done. Exit 
WScript.Quit(0); 

私は、スクリプトを養うためにしようとしているURLはhttp://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=visual&action=advanced&set=[「アラビアン+ナイト」である]

またはalternativly http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=visual&action=advanced&set=[「アラビアンナイト」 ]

問題私はそれを送り、他のURLのいずれも空間を使用していないように空間/ +と思われるか、+

WA私は、HTMLを引くためのスクリプトを呼び出していますyは:

call callurl.cmd "http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=visual&action=advanced&set=["Arabian+Nights"]" 

編集:私だけがMsxml2.XMLHTTP.6.0がMSXML2.ServerXMLHTTPに変更した作られた変更スクリプトがOpen a URL without using a browser from a batch file

からである元のスレッドを発見しました。 6.0では、元のスクリプトがセキュリティのためにサイトを読み込めなかったため、

答えて

4

この場合、問題は、Windowsスクリプティングホストが引数に含まれる二重引用符を消費することです。

npocmakaが表示しましたone of the solutions:URLに引用符をエンコードします。私の見解からは正しいものです(二重引用符は安全でない文字であり、エンコードする必要があります)。

別の解決策は、スクリプトへの引数としてURLを渡すことがないように、しかし、環境変数に格納して、JavaScriptの一部で今すぐ変数

@if (@[email protected]) @then 
@echo off 
rem **** batch zone ********************************************************* 

    setlocal enableextensions disabledelayedexpansion 

    rem Ensure we get a correct reference to current batch file 
    call :getFullBatchReference _f0 

    rem Batch file will delegate all the work to the script engine 
    if not "%~1"=="" (
     set "URL=%~1" 
     cscript //nologo //E:JScript "%_f0%" 
    ) 

    rem Ensure batch ends execution before reaching javascript zone 
    exit /b %errorlevel% 

:getFullBatchReference returnVar 
    set "%~1=%~f0" 
    goto :eof 

@end 
// **** Javascript zone ***************************************************** 
// Instantiate the needed component to make url queries 
var http = WScript.CreateObject('MSXML2.ServerXMLHTTP.6.0'); 

// Retrieve the url parameter from environment variable 
var url = WScript.CreateObject('WScript.Shell') 
      .Environment('Process') 
      .Item('URL'); 

var exitCode = 0; 

    try { 
     // Make the request 
     http.open("GET", url, false); 
     http.send(); 

     // If we get a OK from server (status 200), echo data to console 
     if (http.status === 200) { 
      WScript.StdOut.Write(http.responseText); 
     } else { 
      exitCode = http.status; 
     }; 

    } catch (e) { 
     // Something failed 
     WScript.StdOut.Write('ERROR: ' + e.description); 
     exitCode = 1; 
    }; 

    // All done. Exit 
    WScript.Quit(exitCode); 

から値を取得することで、それを

geturl.cmd "http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=visual&action=advanced&set=["Arabian+Nights"]" 
+0

助けてくれてありがとうございますが、私はまだ出力を得ることができません.HTMLは

+0

@ reddeath68、' geturl.cmd "としてテストhttp://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=visual&action = advanced&set = ["Arabian + Nights"] "'と指示された出力が得られます。何を手に入れますか? –

+0

http://pastebin.com/YRdJrsnSは私が得た出力であり、cmd行に追加されたときにそれが "http://gatherer.wizards.com/Pages/Search/Default.aspx?outpu? 何らかの理由で二重の疑問符 –

0

またはプラス記号+をURLの符号化スペース%20に置き換えてください。

私はこれが全体を解析するために必要になる場合がありかかわらず、スペースをエンコードする必要はなく、むしろ(%22付き)二重引用符と思ういけない

cscript //E:JScript "%~dpnx0" "%~1" 

http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=visual&action=advanced&set=[「アラビア%20Nights」]

+0

スクリプトは%20を正しく解釈していないようですが、バッチファイルから供給されていると思われますか? –

+2

'%'を別の '%'でエスケープする必要があるので、代わりに '%% 20'を使用してください。 – SomethingDark

+0

http://gatherer.wizards.com/Pages/Search/Default.aspxのようなサイトを返すのですか?このような代わりに出力=スポイラー&メソッド=ビジュアル&アクション=高度&設定= [%22Arabian %% 20Nights%22] http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=visual&action=advanced&set= [ %22Arabian%20Nights%22] ill edit私がバッチファイルからスクリプトを呼び出す方法を示す最初の投稿おそらく、それを間違って呼び出すことです。 –

2

コールそんなます。cscriptコマンドライン(%*)あなたはまた、named argumentsで試すことができます

setlocal enableDelayedExpansion 
set "link=%*" 
set "link=!link:"=%%22!" 
.... 
cscript //E:JScript "%~dpnx0" "%link%" 

のようなものを試してみて、スクリプトにコマンドライン全体を渡すことができます。

+0

最初の投稿が表示されているので、スクリプトはjavascriptとバッチの間のハイブリッドであり、投稿にはcallurl.cmdという名前で保存されています。 –

+0

バッチファイルあなたはJSの部分に移動します。 – geisterfurz007

+0

@ geisterfurz007 - はい。私はこの手法を知っています。問題は二重引用符であり、スクリプトは2つの引数があると考えています。 – npocmaka

関連する問題