【发布时间】:2017-01-28 00:43:07
【问题描述】:
我正在使用组合的批处理和 java 脚本,我发现它使用批处理文件从网站检索 html,而我们处理的一个脚本没有返回所需的输出,因为它在我使用 Firefox 中的 url 时出现。
我用来拉取 html 的脚本是:
@if (@This==@IsBatch) @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);
我尝试输入脚本的网址是 http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=visual&action=advanced&set=["Arabian+Nights"]
问题似乎是空格/+,因为我提供给它的其他网址都没有使用空格或 +
我调用脚本来拉取 html 的方式是:
call callurl.cmd "http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=visual&action=advanced&set=["Arabian+Nights"]"
编辑:找到脚本来自Open a URL without using a browser from a batch file的原始线程
我所做的唯一更改是将 Msxml2.XMLHTTP.6.0 更改为 MSXML2.ServerXMLHTTP.6.0,因为原始脚本由于我发现的安全性而无法加载站点。
【问题讨论】:
标签: javascript windows batch-file url space