小编aus*_*ser的帖子

使用Unix工具解析JSON

我正在尝试解析从curl请求返回的JSON,如下所示:

curl 'http://twitter.com/users/username.json' |
    sed -e 's/[{}]/''/g' | 
    awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}'
Run Code Online (Sandbox Code Playgroud)

以上将JSON拆分为字段,例如:

% ...
"geo_enabled":false
"friends_count":245
"profile_text_color":"000000"
"status":"in_reply_to_screen_name":null
"source":"web"
"truncated":false
"text":"My status"
"favorited":false
% ...
Run Code Online (Sandbox Code Playgroud)

如何打印特定字段(用-v k=text?表示)?

bash parsing json

794
推荐指数
25
解决办法
87万
查看次数

Nightmare.js屏幕截图缓冲区长度为0

我正在运行一个nightmare.js脚本,我试图在页面上截取多个元素.

捕获的第一个元素很好,但是折叠下方的每个其他元素都以零长度捕获.我正在努力调试这个问题.任何帮助都会非常感激.

基本上,此脚本遍历页面并选择页面上与选择器匹配的所有元素.然后,使用async它收集响应并返回对象的缓冲区.问题是折叠下方的元素没有截屏(缓冲区长度最终为零).我试图wait()滚动到元素,但我还没有取得任何成功.

import * as Nightmare from 'nightmare'
import * as vo from 'vo'
import * as async from 'async'
import * as fs from 'fs'

const urls:String[] = [
  'https://yahoo.com/'
]


Nightmare.action('snap', function(selector:String, done:Function) {
  const self = this;

  this.evaluate_now(function (selector) {
    return Array.from(document.querySelectorAll(selector))
    .map((ele:Element) => {
      if (ele) {
        const rect = ele.getBoundingClientRect()
        const r:Function = Math.round
        return {
          x: r(rect.left),
          y: r(rect.top),
          width: r(rect.width),
          height: r(rect.height)
        }
      } …
Run Code Online (Sandbox Code Playgroud)

javascript screenshot typescript nightmare

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

标签 统计

bash ×1

javascript ×1

json ×1

nightmare ×1

parsing ×1

screenshot ×1

typescript ×1