(htmlContent, pageNum, pages, callback)
| 785 | |
| 786 | // 处理获取到的页面内容 |
| 787 | function processPageContent(htmlContent, pageNum, pages, callback) { |
| 788 | const parser = new DOMParser() |
| 789 | const doc = parser.parseFromString(htmlContent, 'text/html') |
| 790 | const divElements = doc.querySelectorAll('div.relative.aspect-w-16.aspect-h-9.rounded.overflow-hidden.shadow-lg') |
| 791 | const logEntry = { |
| 792 | url: `${processUrl(inurl)}${pageNum}`, |
| 793 | elementsFetched: divElements.length |
| 794 | } |
| 795 | |
| 796 | // 如果当前名称的日志组不存在,则创建一个新数组 |
| 797 | if (!downloadLog[name]) { |
| 798 | downloadLog[name] = [] |
| 799 | } |
| 800 | |
| 801 | // 将日志条目添加到日志数组中 |
| 802 | downloadLog[name].push(logEntry) |
| 803 | if (divElements.length === 0) { |
| 804 | const logEntry = { |
| 805 | url: `${processUrl(inurl)}${pageNum}`, |
| 806 | elementsFetched: 0, // 这里可以根据实际需求设置其他信息 |
| 807 | errorMessage: `获取第 ${pageNum} 页失败。` |
| 808 | } |
| 809 | if (!errorLogs[name]) { |
| 810 | errorLogs[name] = [] |
| 811 | } |
| 812 | errorLogs[name].push(logEntry) |
| 813 | console.log(`获取第 ${pageNum} 页失败。`) |
| 814 | window.addToLog(`${name}${processUrl(inurl)}${pageNum}+获取失败 数量:` + divElements.length, 'error') |
| 815 | } |
| 816 | |
| 817 | divElements.forEach(div => { |
| 818 | var imgUrl = div.querySelector('img').getAttribute('data-src') |
| 819 | |
| 820 | if (shouldReplace) { |
| 821 | imgUrl = imgUrl.replace('cover-t.jpg', 'cover-n.jpg') |
| 822 | } |
| 823 | const video = { |
| 824 | fileName: div.querySelector('a').getAttribute('alt'), |
| 825 | imgUrl: imgUrl, |
| 826 | videoUrl: div.querySelector('video').getAttribute('data-src'), |
| 827 | markContent: Array.from(div.querySelectorAll('span')).map(mark => mark.textContent).join(' '), |
| 828 | altText: div.querySelector('img').getAttribute('alt'), |
| 829 | jumpUrl: div.querySelector('a').getAttribute('href') |
| 830 | |
| 831 | } |
| 832 | |
| 833 | if (saveVideoInfo) { |
| 834 | video.info = extractInformation(video.jumpUrl) |
| 835 | //showBanner(`正在获取 ${video.fileName} 信息`); |
| 836 | window.addToLog(`正在获取 ${video.fileName} 信息`, 'info') |
| 837 | console.log() |
| 838 | } |
| 839 | |
| 840 | if (video.imgUrl && video.altText) { |
| 841 | videos.push(video) |
| 842 | if (saveImage) { |
| 843 | window.addToLog('保存' + video.imgUrl, 'info') |
| 844 | pendingRequests++ |
no test coverage detected