2

JS 中如何让 String 继承 getElement

 3 years ago
source link: https://www.v2ex.com/t/781984
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  JavaScript

JS 中如何让 String 继承 getElement

  zhuzhuaini · 21 分钟前 · 61 次点击

目前在学习 JS,主要目的是写一个油猴脚本,我的理解是油猴中写的 JS 脚本可以外挂在需要执行的网页当中。

目前我的需求是,先获取网页当中的 href 超链接(目前已经实现)

然后通过油猴的“GM_xmlhttpRequest”去访问这个超链接,并返回源码(这一步也已经实现)

剩下的就是解析源码了,但是我也需要获取源码中的节点嘛,那我本来获取 href 超链接可以使用 document.getElementsByClassName 的方式去获取,但现在返回回来的源码是一个 String 类型的数据,他没法使用类似 getElementsByClassName 的方法去定位,所以我来问问有没有什么方法可以实现让 String 数据继承,如果没有的话,我就要想办法用正则去实现了。。。

我看了其他人写的代码,基本上都用到了一些库可以解析,比如 request,Cheerio 啥的,但是我琢磨了下发现都似乎无法在油猴上实现导入这些库。

如果各位大佬有更好的方案也请指教。。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK