| | |
| | | |
| | | function getBookInfo(book) { |
| | | return retry(async () => { |
| | | book.publisher = await driver.executeScript(`return document.querySelector("span[itemprop=publisher]").textContent`).catch(e=>0); |
| | | book.pubDate = await driver.executeScript(`return document.querySelector("span[itemprop=datePublished]").textContent`).catch(e=>0); |
| | | let pages = await driver.executeScript(`return document.querySelector("span[data-id=resultsCount]").textContent`).catch(e=>0); |
| | | book.publisher = await driver.executeScript(`return document.querySelector("span[itemprop=publisher]").textContent`).catch(e => 0); |
| | | book.pubDate = await driver.executeScript(`return document.querySelector("span[itemprop=datePublished]").textContent`).catch(e => 0); |
| | | let pages = await driver.executeScript(`return document.querySelector("span[data-id=resultsCount]").textContent`).catch(e => 0); |
| | | if (pages) { book.pages = pages.split(' / ')[1]; } |
| | | }); |
| | | } |
| | |
| | | try { |
| | | await downloadFile(book, url); |
| | | console.log(`下载完成: ${book.id} ${book.title}`); |
| | | console.log('finish: '+JSON.stringify(book)); |
| | | console.log('finish: ' + JSON.stringify(book)); |
| | | } catch (e) { } |
| | | successCount++; |
| | | // 等一段时间再下一个 |
| | |
| | | for (const book of books) { |
| | | const index = data.findIndex((row) => row[0] === book.id); |
| | | if (index > -1) { |
| | | data[index][5] = book.publisher; |
| | | data[index][6] = book.pubDate; |
| | | data[index][11] = book.pages; |
| | | data[index][12] = book.state; |
| | | data[index][13] = book.format; |
| | | data[index][14] = book.file; |