在处理网络抓取项目时,我无法以统一的方式获取某些数据。该页面有一个双列表,我只需要抓取第二列的文本即可运行编译值。
我正在这样做:
const rq = require('request');
const cheerio = require('cheerio');
rq(url, (err, res, html) => {
let $ = cheerio.load(html);
$('#table-id > tbody > tr > td.data').toArray().map(item => {
console.log(item.text());
});
});
Run Code Online (Sandbox Code Playgroud)
但是我收到一个.text()不是函数的错误。
我有一个带有对象数组的 json,每个对象都有自己的子数组。
我想使用传递给 Handlebars js 的 _Year 变量中的值从 _History 子数组中获取值。如果我将值直接设置到代码 ex: 中,我可以让它工作{{_History.[2018].Testa}}。
是否可以设置 _Year 的值并使车把获得正确的子数组?
我传递给把手 js 的参数值。
var params = {
_Person: "THE JSON",
_Year: "2018"
};
Run Code Online (Sandbox Code Playgroud)
JSON 代码:
[
{
"_History": {
"2017": {
"Testa": "Test 1",
"Testb": "Test 2"
},
"2018": {
"Testa": "Test 3",
"Testb": "Test 4"
}
},
"FirstName": "John",
"LastName": "Doe"
},
{
"_History": {
"2017": {
"Testa": "Test 5",
"Testb": "Test 6"
},
"2018": {
"Testa": "Test 7",
"Testb": "Test 8" …Run Code Online (Sandbox Code Playgroud) 我正在尝试使两个异步调用同时运行并等待它们完成Promise.all。如何Promise.all在 Node.js 的 es6 中使用 async/await 返回多个值?我希望我能在外面看到分配的变量。这段代码是错误的,但代表了我所需要的。
Promise.all([
var rowA = await buildRow(example, countries),
var rowM = await buildRow(example, countries)
])
console.log(rowA+rowB)
Run Code Online (Sandbox Code Playgroud)
有没有办法查看范围之外的这些变量?
我试图让 JS 加载一个网站,然后单击两个按钮。第一个按钮点击并通过,但第二个按钮抛出此错误
const ATC_Button = driver.wait(
webdriver.until.elementLocated({ name: 'commit' }),
20000
);
const GTC_Button = driver.wait(
webdriver.until.elementLocated({ xpath: '//*[@id="cart"]/a[2]' }),
20000
);
ATC_Button.click();
GTC_Button.click();
Run Code Online (Sandbox Code Playgroud)
错误:
(node:21408) UnhandledPromiseRejectionWarning: WebDriverError: element not visible
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 10.0.16299 x86_64)
at Object.checkLegacyResponse (C:\New folder\JS\Bot V1\MYBot\node_modules\selenium-webdriver\lib\error.js:585:15)
at parseHttpResponse (C:\New folder\JS\Bot V1\MYBot\node_modules\selenium-webdriver\lib\http.js:533:13)
at Executor.execute (C:\New folder\JS\Bot V1\MYBot\node_modules\selenium-webdriver\lib\http.js:468:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:21408) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function
without a …Run Code Online (Sandbox Code Playgroud)