我正在尝试解析从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?表示)?
我正在运行一个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)