15楼#
发布于:2024-04-15 10:15
fanta:hello,大神,好久不见,我又来向您求助了 看不懂html代码就去学啊,十多年前我也是用firebug边看html结构边学jquery的。现在自带的F12开发工具比当年的firebug强大多了,一年过去了怎么这点长进都没有 open("https://home.zongheng.com/people/" + window.__NUXT__.state.detail.detailBook.authorInfo.authorId, "_blank"); document.querySelectorAll('.detail-catalog--chapter .chapter-list--item-main').forEach((a)=>{ console.log(a.textContent) });或者直接用它的api了,不跟html纠缠,就不用等它把目录加载完毕 fetch("https://bookapi.zongheng.com/api/chapter/getChapterList", { method: "POST", headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: "bookId=" + window.__NUXT__.state.detail.detailBook.book.bookId, }).then(async (data)=>{ let response = await data.json(); if (response.code == 0) { for (const tome of response.result.chapterList) { for (const chap of tome.chapterViewList) { console.log(tome.tome.tomeName + "-" + chap.chapterName) } } } }); |
|
16楼#
发布于:2024-04-15 16:26
|
|
17楼#
发布于:2024-04-15 17:44
|
|
18楼#
发布于:2024-04-15 18:32
taoww:首先去查看页面源代码,搜索看有没有包含 window.__NUXT__= 这么一段脚本的script。 // ==UserScript== // @name why // @version 0.1 // @description books. // @match https://www.zongheng.com/detail/* // @require https://code.jquery.com/jquery-3.6.1.min.js // ==/UserScript== /* globals jQuery, $, waitForKeyElements */ (function() { 'use strict'; console.log('test'); open("https://home.zongheng.com/people/" + window.__NUXT__.state.detail.detailBook.authorInfo.authorId, "_blank"); document.querySelectorAll('.detail-catalog--chapter .chapter-list--item-main').forEach((a)=>{ console.log(a.textContent) }); })(); 把@run-at设置成了document-start ..没用过..嘿嘿... 搜索window.__NUXT__是有的 window.__NUXT__ = (function(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D) { |
|
19楼#
发布于:2024-04-15 18:38
taoww:首先去查看页面源代码,搜索看有没有包含 window.__NUXT__= 这么一段脚本的script。firefox 报错是Uncaught (in promise) TypeError: window.__NUXT__ is undefined safari报错是Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'window.__NUXT__.state') |
|
20楼#
发布于:2024-04-15 20:21
fanta:// ==UserScript==我试了下,是因为tampermonkey实现了个沙盒,你这样写没法取得页面环境中window的属性 在// ==/UserScript==之前加一行 // @grant none禁止掉沙盒就能正常工作了。 或者加上 // @grant unsafeWindow再把代码中的window改成unsafeWindow,可以保留沙盒 |
|
21楼#
发布于:2024-04-15 22:46
taoww:我试了下,是因为tampermonkey实现了个沙盒,你这样写没法取得页面环境中window的属性加上// @grant none确实不报错了,但是console.log(a.textContent)什么也没输出啊,只能输出我加的'test' // ==UserScript== // @name why // @version 0.1 // @description books. // @match https://www.zongheng.com/detail/* // @require https://code.jquery.com/jquery-3.6.1.min.js // @grant none // ==/UserScript== /* globals jQuery, $, waitForKeyElements */ (function() { 'use strict'; console.log('test'); open("https://home.zongheng.com/people/" + window.__NUXT__.state.detail.detailBook.authorInfo.authorId, "_blank"); document.querySelectorAll('.detail-catalog--chapter .chapter-list--item-main').forEach((a)=>{ console.log(a.textContent) }); console.log('test2'); })(); |
|
22楼#
发布于:2024-04-15 23:23
我猜是需要加入代码等待载入完成,可是我用百度搜到的没成功...
不过,我又测试了您说的第二种办法,成功取得了章节列表 现在就是还存在我提问的第一个问题,这个链接怎么获取 1.如何获取 点击右侧作者名字 或 作者头像 跳转到作者所有作品的链接,就是如何获取这个地址https://home.zongheng.com/people/19335221 |
|
23楼#
发布于:2024-04-15 23:53
|
|
24楼#
发布于:2024-04-16 00:23
无论如何感谢帮忙,我太笨后续一些还是搞不定,先这样,我有空再折腾
|
|
上一页
下一页