如何在多个表内深入获取每个元素的innerText?(chrome扩展名)

我已经尝试了几个小时(我是网络开发的新手)。 我需要访问一个包含许多列的表,其中一列包含人名的行,并将它们放在数据结构中。 在每一行中,包含此人姓名的文本的ID设置如下:

 JOHN DOE  == $0  BOB DAVID  == $0 

这些行在表格等表格中非常非常深…

我试过了

 var n = document.getElementsByClassName(".myClass"); 

 var n = document.querySelectorAll(".myClass"); 

 n = $(".myClass"); 

但没有运气。

是否有不同的方法来访问此结构内部的某些类/ ID?

编辑:有多个接近的答案,但我接受了最愿意帮助的用户,并且主要针对我的特定情况量身定制。

更新

有可能动态创建.PSLONGEDITBOX ,并且在调用脚本时它不存在于DOM中。 更新的演示将调用脚本onDOMReady ,然后第二次onload ,这是可能的最新加载事件。

详细信息在演示中进行了评论


演示

 // This loads dataArray() when DOM is ready $(function() { var onDOM = dataArray(); console.log('onDOMReady: ' + onDOM); }); function dataArray() { // Declare empty array var boxArray = []; /* .each() .PSLONGEDITBOX extract it's text || with .text() method then || .push() extracted text into the empty array */ $('.PSLONGEDITBOX').each(function(idx, box) { let content = $(this).text(); boxArray.push(content); }); return boxArray; } function onLoadEvent(fnc) { // assign any functions on 'window.onload' to a var var onLoad = window.onload; // if there isn't any function on 'window.onload'... if (typeof window.onload != 'function') { // Assign fnc to it... window.onload = fnc; let F = fnc(); console.log('onLoad: ' + F); // Otherwise... } else { window.onload = function() { // Call the function that's there already... onLoad(); console.log('Original function loaded...'); // ...then call fnc fnc(); let F = fnc(); console.log('onLoad: ' + F); } } } /* Both expressions will run dataArray after everything || else has loaded. This is the onload event, which is || the most thorough of loading events and the slowest. || Besides being the last event, it's other major con || is that only one function can be called, any others || called before the last function called is overridden. || The function onLoadEvent() is designed to find any || previously assigned function or method to the onload || event and then invoke it first, then invoke any || given function afterwards. */ /* add a '/' to enable expression below. var onLoad = dataArray(); window.onload = console.log('onLoad Event: ' + onLoad); /*/ //* Remove a '/' to disable function below onLoadEvent(dataArray); 
  
   
 
 
ABC
DEF
GHI
JKL
MNO

这个

 n = $(".PSLONGEDITBOX"); 

应该管用。 但它不会返回文本,它会将SPAN元素作为对象返回。 得到你需要的文字

 n = $(".PSLONGEDITBOX").text(); 

我认为这不取决于HTML的结构。 你用$(文件).ready吗? 或者也许你应该在页面上的结束体附近包含你的js文件。