小编ngm*_*ney的帖子

在python中计算网页大小

我将如何使用Python计算网页(url)的大小.我尝试了urllib2并抓住了内容长度标题,但它不存在.

import urllib2
url = 'http://www.google.com/'
r = urllib2.urlopen(url)
#Not sure what to do from here
Run Code Online (Sandbox Code Playgroud)

python

2
推荐指数
1
解决办法
3328
查看次数

检索node.js child_process的结果

我无法绕过node.js的异步性质.让我们假设我想要一个执行'ls'命令的路由并将结果(作为字符串)返回给浏览器.如何使用child_process.exec进行此操作?以下是不正确的,但沿着我正在努力的方向:

function dir_list() {
  var sys = require('sys');
  var exec = require('child_process').exec
  child = exec('ls -la', function(error, stdout, stderr) {
    //I would like to return stdout but can't figure out how
    return stdout;
  });
  return child;
}

app.get('/', function(req, res){
  res.render('index', {
  title: 'MyPage',
  subtitle: 'Below is a directory listing',
  results: dir_list()
});
Run Code Online (Sandbox Code Playgroud)

这不是我的app.js的整个代码,但基本上我正在寻找帮助,让dir_list()将结果变量设置为"ls -la"的输出.

node.js

1
推荐指数
1
解决办法
4968
查看次数

标签 统计

node.js ×1

python ×1