Skip to content

Commit 210a8dc

Browse files
committed
update selector
1 parent d50dddc commit 210a8dc

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

pkg/aiqicha/search.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ const sleep = async (ms) => {
254254
}
255255
}
256256
function getNext_Control() {
257-
var tbody = document.querySelectorAll('#basic-hold > div > ul > li');
257+
var tbody = document.querySelectorAll('#basic-hold > div > div > ul > li');
258258
if (tbody.length == 0) {
259259
return false
260260
}
261261
if (tbody[tbody.length - 1].className.indexOf('disabled') == -1) {
262-
document.querySelector('#basic-hold > div > ul > li.ivu-page-next > a').click();
262+
document.querySelector('#basic-hold > div > div > ul > li.ivu-page-next > a').click();
263263
return true
264264
}
265265
return false
@@ -290,11 +290,12 @@ const sleep = async (ms) => {
290290
console.log("bufsnake control " + value.trim());
291291
}
292292
}
293-
await sleep(2000);
294293
if (!getNext_Control()) {
295294
break
296295
}
296+
await sleep(2000);
297297
}
298+
await sleep(2000);
298299
}
299300
control()
300301
`
@@ -315,10 +316,13 @@ const sleep = async (ms) => {
315316
}
316317
// 存在: HTMLHeadingElement
317318
if result.ClassName == "HTMLLIElement" {
318-
return chromedp.WaitVisible("#basic-hold > div > ul > li.ivu-page-next.ivu-page-disabled > a > i").Do(ctx)
319+
// 下一页为display: none导致WaitVisible不可用
320+
// REF: https://github.com/chromedp/chromedp/issues/262
321+
return chromedp.WaitReady("#basic-hold > div > ul > li.ivu-page-next.ivu-page-disabled > a > i").Do(ctx)
319322
}
320323
return
321324
}),
325+
chromedp.Sleep(2 * time.Second),
322326
// 对外投资
323327
chromedp.ActionFunc(func(ctx context.Context) (err error) {
324328
defer func() {
@@ -346,12 +350,12 @@ const sleep = async (ms) => {
346350
}
347351
348352
function getNext_invest() {
349-
var tbody = document.querySelectorAll('#basic-invest > div > ul > li');
353+
var tbody = document.querySelectorAll('#basic-invest > div > div > ul > li');
350354
if (tbody.length == 0) {
351355
return false
352356
}
353357
if (tbody[tbody.length - 1].className.indexOf('disabled') == -1) {
354-
document.querySelector('#basic-invest > div > ul > li.ivu-page-next > a').click();
358+
document.querySelector('#basic-invest > div > div > ul > li.ivu-page-next > a').click();
355359
return true
356360
}
357361
return false
@@ -365,11 +369,13 @@ const sleep = async (ms) => {
365369
console.log("bufsnake invest "+path[1].querySelector('div > div.title.portrait-text > a.ellipsis-line-2').innerText +
366370
" " + path[4].innerText + " " + path[6].innerText);
367371
}
368-
await sleep(2000);
369372
if (!getNext_invest()) {
373+
console.log("对外投资获取完成")
370374
break
371375
}
376+
await sleep(2000);
372377
}
378+
await sleep(2000);
373379
}
374380
invest()
375381
`
@@ -390,10 +396,11 @@ const sleep = async (ms) => {
390396
}
391397
// 存在: HTMLHeadingElement
392398
if result.ClassName == "HTMLDivElement" {
393-
return chromedp.WaitVisible("#basic-invest > div.aqc-table-list-pager > ul > li.ivu-page-next.ivu-page-disabled > a > i").Do(ctx)
399+
return chromedp.WaitReady("#basic-invest > div.aqc-table-list-pager > div > ul > li.ivu-page-next.ivu-page-disabled").Do(ctx)
394400
}
395401
return
396402
}),
403+
chromedp.Sleep(2 * time.Second),
397404
//工商注册
398405
chromedp.ActionFunc(func(ctx context.Context) (err error) {
399406
defer func() {
@@ -431,6 +438,7 @@ console.log("bufsnake business "+JSON.stringify(output))
431438
}
432439
return err
433440
}),
441+
chromedp.Sleep(2 * time.Second),
434442
// 股东信息
435443
chromedp.ActionFunc(func(ctx context.Context) (err error) {
436444
defer func() {
@@ -458,12 +466,12 @@ if (typeof eval('sleep') !== "function") {
458466
}
459467
460468
function getNext_shareholders() {
461-
var tbody = document.querySelectorAll('#basic-shareholders > div > ul > li');
469+
var tbody = document.querySelectorAll('#basic-shareholders > div > div > ul > li');
462470
if (tbody.length == 0) {
463471
return false
464472
}
465473
if (tbody[tbody.length - 1].className.indexOf('disabled') == -1) {
466-
document.querySelector('#basic-shareholders > div > ul > li.ivu-page-next > a').click();
474+
document.querySelector('#basic-shareholders > div > div > ul > li.ivu-page-next > a').click();
467475
return true
468476
}
469477
return false
@@ -477,11 +485,12 @@ const shareholders = async () => {
477485
console.log("bufsnake shareholders " + path[1].innerText.replaceAll('\n', " ").replaceAll("股权结构",
478486
" ").replaceAll(">", " ").trim().replaceAll(" ", "-") + " " + path[2].innerText);
479487
}
480-
await sleep(2000);
481488
if (!getNext_shareholders()) {
482489
break
483490
}
491+
await sleep(2000);
484492
}
493+
await sleep(2000);
485494
}
486495
shareholders()`
487496
_, exception, err = runtime.Evaluate(auto).Do(ctx)
@@ -501,10 +510,11 @@ shareholders()`
501510
}
502511
// 存在: HTMLHeadingElement
503512
if result.ClassName == "HTMLDivElement" {
504-
return chromedp.WaitVisible("#basic-shareholders > div.aqc-table-list-pager > ul > li.ivu-page-next.ivu-page-disabled > a > i").Do(ctx)
513+
return chromedp.WaitReady("#basic-shareholders > div.aqc-table-list-pager > div > ul > li.ivu-page-next.ivu-page-disabled > a > i").Do(ctx)
505514
}
506515
return
507516
}),
517+
chromedp.Sleep(2 * time.Second),
508518
chromedp.Click("body > div.base.page-detail.has-search-tab > div.aqc-content-wrapper.has-footer > div > div.tab-wrapper > div > div > div:nth-child(3) > a"),
509519
chromedp.Sleep(2 * time.Second),
510520
// 网站备案
@@ -533,12 +543,12 @@ if (typeof eval('sleep') !== "function") {
533543
}
534544
535545
function getNext_webRecord() {
536-
var tbody = document.querySelectorAll('#certRecord-webRecord > div > ul > li');
546+
var tbody = document.querySelectorAll('#certRecord-webRecord > div > div > ul > li');
537547
if (tbody.length == 0) {
538548
return false
539549
}
540550
if (tbody[tbody.length - 1].className.indexOf('disabled') == -1) {
541-
document.querySelector('#certRecord-webRecord > div > ul > li.ivu-page-next > a').click();
551+
document.querySelector('#certRecord-webRecord > div > div > ul > li.ivu-page-next > a').click();
542552
return true
543553
}
544554
return false
@@ -551,11 +561,12 @@ const webRecord = async () => {
551561
var path = tbody[i].querySelectorAll('td');
552562
console.log("bufsnake webRecord "+path[1].innerText.replaceAll("\n",";") + " " + path[2].innerText.replaceAll("\n",";") + " " + path[4].innerText.replaceAll("\n",";"));
553563
}
554-
await sleep(2000);
555564
if (!getNext_webRecord()) {
556565
break
557566
}
567+
await sleep(2000);
558568
}
569+
await sleep(2000);
559570
}
560571
webRecord()`
561572
_, exception, err = runtime.Evaluate(auto).Do(ctx)
@@ -575,10 +586,11 @@ webRecord()`
575586
}
576587
// 存在: HTMLHeadingElement
577588
if result.ClassName == "HTMLDivElement" {
578-
return chromedp.WaitVisible("#certRecord-webRecord > div.aqc-table-list-pager > ul > li.ivu-page-next.ivu-page-disabled > a > i").Do(ctx)
589+
return chromedp.WaitReady("#certRecord-webRecord > div.aqc-table-list-pager > div > ul > li.ivu-page-next.ivu-page-disabled > a > i").Do(ctx)
579590
}
580591
return
581592
}),
593+
chromedp.Sleep(2 * time.Second),
582594
chromedp.ActionFunc(func(ctx context.Context) error {
583595
return target.CloseTarget(chromedp.FromContext(ctx).Target.TargetID).Do(cdp.WithExecutor(ctx, chromedp.FromContext(ctx).Browser))
584596
}),

pkg/log/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func Shareholders(name, data string) {
222222
data = strings.ReplaceAll(data, "bufsnake shareholders ", "")
223223
split := strings.Split(data, " ")
224224
if len(split) == 2 {
225-
fmt.Println(name, "股东", split[0], split[1])
225+
fmt.Println(name, "股东", split[0], strings.TrimRight(split[1], " \r\n\t持股详情>"))
226226
shareholders = append(shareholders, shareholders_struct{
227227
currEnt: name,
228228
entName: split[0],

0 commit comments

Comments
 (0)