在unix中从列名获取值

jmo0nnb3  于 2023-02-22  发布在  Unix
关注(0)|答案(1)|浏览(169)
val=$(curl https://www.geeksforgeeks.org | tr '\n' ' ' | tr -s [[:space::]] | grep -E client_id -e publication_id)

我需要从curl命令中获取特定的值:

Sample I/P:
client_id:"15647",publication_id:["151","152","153"]

输出:
出版物标识:["151"、"152"、"153"]
我想使用grep命令从UNIX中的curl命令获取publication_id值并存储在变量中

3htmauhk

3htmauhk1#

一个包含nodejsxidelxpathpuppeteer的解决方案,正如评论中所说,您需要一个js感知工具:
Javascript wget.js代码(这只是为了模仿wget,它的输出仅为HTML,也是由js生成的):

const puppeteer = require('puppeteer');

(async () => {
    var url = process.argv[2];
    const browser = await puppeteer.launch({headless: true});
    const page = await browser.newPage();
    await page.goto(url, { waitUntil: 'networkidle2' });
    const html = await page.evaluate(() => document.documentElement.outerHTML);
    console.log(html);
    browser.close();
})()

代码:

node wget.js 'https://www.geeksforgeeks.org' |
    xidel -e '//div[@id="g_id_onload"]/@data-client_id'

输出:

388036620207-3uolk1hv6ta7p3r9l6s3bobifh086qe1.apps.googleusercontent.com

相关问题