我有一个来自不同域的远程页面的URL ,我必须下载,解析和更新当前页面的DOM.我已经找到了使用新的ActiveXObject("Msxml2.XMLHTTP")执行此操作的示例,但我认为这仅限于IE,并且使用新的java.net.URL,但我不想使用Java.还有其他选择吗?
我可能缺少一些细节,因为光栅化脚本可以很好地独立工作,但到目前为止我还没有成功地从NodeJS读取它的输出.
这是NodeJS的一部分:
var http = require('http');
var qs = require('querystring');
var fs = require('fs');
var spawn = require('child_process').spawn;
var SCRIPT = fs.readFileSync('./script.js', { encoding: 'utf8' });
http.createServer(function (request, response) {
var body = '';
request.on('data', function (data) {
body += data;
});
request.on('end', function () {
var postData = qs.parse(body);
var phantomOut = '';
var phantom = spawn('phantomjs');
phantom.stdout.on('data', function (buf) {
phantomOut += buf;
});
phantom.on('exit', function (code) {
response.writeHead(200, {
'Content-Type': 'image/png'
});
response.end(phantomOut);
});
phantom.stdin.setEncoding('utf8');
phantom.stdin.write( SCRIPT.replace('(#imageData)', …Run Code Online (Sandbox Code Playgroud) 我正在使用 async/await 发出数千个 HTTP 请求,并希望有一个进度指示器。我以一种天真的方式添加了一个,但注意到当所有请求都完成时,计数器值永远不会达到总数。所以我创建了一个简单的测试,果然,它没有按预期工作:
fun main(args: Array<String>) {
var i = 0
val range = (1..100000)
range.map {
launch {
++i
}
}
println("$i ${range.count()}")
}
Run Code Online (Sandbox Code Playgroud)
输出是这样的,第一个数字总是改变:
98800 100000
Run Code Online (Sandbox Code Playgroud)
我可能在 JVM/Kotlin 中遗漏了一些关于并发/同步的重要细节,但不知道从哪里开始。有小费吗?
更新:我最终按照 Marko 的建议使用了频道:
/**
* Asynchronously fetches stats for all symbols and sends a total number of requests
* to the `counter` channel each time a request completes. For example:
*
* val counterActor = actor<Int>(UI) {
* var counter = 0
* for (total in channel) …Run Code Online (Sandbox Code Playgroud) 如果可以将想法实现为桌面应用程序和Web应用程序,那么您会采用哪种方式?
我在这里有点偏颇,因为我倾向于选择桌面应用而不是网络应用,因为它能够快速访问信息:无需打开浏览器,无需登录,响应速度更快,托盘集成,通知,全球热键等.作为开发人员,我也有更多开发桌面应用程序的经验.但作为ISV,我不仅要担心不仅丰富用户,还要丰富自己;)
我该怎么做?
星期二,2010年2月2日19:34:21等等/ GMT
这两种声明在性能方面有什么区别吗?
local object = newObject()
function object:method(params)
end
local object:method = function(params)
end
Run Code Online (Sandbox Code Playgroud) 我在下面编写了PHP函数来下载文件,它可以按预期工作。但是,当我尝试下载此文件时:
$url = 'http://javadl.sun.com/webapps/download/GetFile/1.7.0_02-b13/windows-i586/jre-7u2-windows-i586-iftw.exe';
download($url);
Run Code Online (Sandbox Code Playgroud)
...没有内容写入文件。我不知道为什么。创建文件后,对curl_exec的调用返回true,但是输出文件保持为空。可以在浏览器中很好地下载文件,并且该功能可以成功下载其他文件。我遇到的只是这个文件(主机?)。
任何帮助表示赞赏。
function download($url)
{
$outdir = 'C:/web/www/download/';
// open file for writing in binary mode
if (!file_exists($outdir)) {
if (!mkdir($outdir)) {
echo "Could not create download directory: $outdir.\n";
return false;
}
}
$outfile = $outdir . basename($url);
$fp = fopen($outfile, 'wb');
if ($fp == false) {
echo "Could not open file: $outfile.\n";
return false;
}
// create a new cURL resource
$ch = curl_init();
// The URL to fetch
curl_setopt($ch, CURLOPT_URL, $url);
// The …Run Code Online (Sandbox Code Playgroud) 比如,我们在商店中有以下内容:
{
"document": {
"success": "true",
"totalAllocation": "40000000.00",
"fundAllocation": [
{
"fundName": "Zais Opportunity Ltd Class B",
"allocation": "10000000.00"
},
{
"fundName": "Metacapital Mortgage Opportunities Ltd",
"allocation": "10000000.00"
},
...
]
}
}
Run Code Online (Sandbox Code Playgroud)
而我想做的是这样的事情:
itemTpl: Ext.create('Ext.XTemplate',
'<div>',
'<span>{fundName}</span>',
'<span>{[this.getPercentage(values.allocation, parent.totalAllocation)]}%</span>',
'</div>',
{
getPercentage: function (allocation, totalAllocation) {
return Ext.Number.toFixed(allocation / totalAllocation, 2);
}
}
)
Run Code Online (Sandbox Code Playgroud)
但是,当然,这不起作用,因为此范围内的"父"是空的.
知道如何获取XTemplate基金内的totalAllocation字段的值,以显示在列表项中分配给当前基金的百分比?也欢迎变通方法.
每个文档都有一个日期属性,每当修改文档时,都会使用新的MongoDate()进行更新.
如何才能获得N个最后修改过的文件?但不是因为某些特定日期.只有最新日期的N个文件.也许像sort这样的东西不是游标方法,但是查询参数存在?