nodejs_chromium 1.1.13 → 1.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/chrome.js +41 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs_chromium",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
4
4
  "description": "for pupeteer chromium",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/chrome.js CHANGED
@@ -305,15 +305,18 @@ module.exports = class {
305
305
  */
306
306
  async elements(tag1, tag2, call) {
307
307
  try {
308
+
308
309
  const div = await this.page.$(tag1);
309
310
  if (!div) {
310
311
  throw new Error(`${tag1} not exists`);
311
312
  }
313
+ let index = 0;
312
314
  for (const elm of (await div.$$(tag2))) {
313
315
  const html = await elm.evaluate(node => node.outerHTML);
314
316
  const text = await elm.evaluate(node => node.innerHTML);
315
- call(elm, { html, text });
317
+ call(elm, { html, text, index: index++ });
316
318
  }
319
+
317
320
  }
318
321
  catch (e) {
319
322
  console.log('[chrome.elements.Error]', e.message)
@@ -321,6 +324,40 @@ module.exports = class {
321
324
  }
322
325
 
323
326
 
327
+ /**
328
+ * 遍历tag1里的tag2,并由call判断,只有call返回true时才resolve
329
+ *
330
+ * @param {Object} tag1
331
+ * @param {Object} tag2
332
+ * @param {Object} call
333
+ */
334
+ async search(tag1, tag2, call) {
335
+ return await new Promise(async (resolve) => {
336
+ try {
337
+
338
+ const div = await this.page.$(tag1);
339
+ if (!div) {
340
+ throw new Error(`${tag1} not exists`);
341
+ }
342
+ let index = 0;
343
+ for (const ele of (await div.$$(tag2))) {
344
+ index++;
345
+ const html = await ele.evaluate(node => node.outerHTML);
346
+ const text = await ele.evaluate(node => node.innerHTML);
347
+ let val = call(ele, { html, text, index });
348
+ if (val === true) return resolve({ success: true, ele, html, text, index });
349
+ }
350
+ resolve({ success: false });
351
+
352
+ }
353
+ catch (e) {
354
+ console.log('[chrome.elements.Error]', e.message)
355
+ }
356
+ });
357
+
358
+ }
359
+
360
+
324
361
  /**
325
362
  * 支持css普通选择器方式和伪类方式
326
363
  * div.body
@@ -444,8 +481,8 @@ module.exports = class {
444
481
  async click(el, option = {}) {
445
482
  try {
446
483
  let { delay = 100, count = 1, x = 6, y = 3 } = option;
447
- await this.page.click(el, { delay, count, offset: { x, y } });
448
- return this;
484
+ return await this.page.click(el, { delay, count, offset: { x, y } });
485
+ // return this;
449
486
  }
450
487
  catch (e) {
451
488
  console.log('[chrome.click.Error]', e.message);
@@ -596,6 +633,7 @@ module.exports = class {
596
633
  }
597
634
 
598
635
  skipTypes = ['image', 'font', 'other', 'script', 'stylesheet', 'document', 'ping'];
636
+
599
637
  setSkipType(items) {
600
638
  this.skipTypes.length = 0;
601
639
  this.skipTypes = [...items];