我正在尝试使用chrome'visument'&gt;&gt;'console'中的javscript从html <table>
收集数据,该数据扩展到多个页面。到目前为止,我可以成功:
但是,在打开任何其他页面后,附加数据始终对应于第一页。因此,不是来自13页的数据,而是从第1页获得数据重复13次。这是代码:
// 'mypage' contains 13 pages of tabular data. Each page is accessed with '&page='
var page = "mypage/?q=&page=";
var pages = 13;
var arr = [];
// loop through all pages
for( var i=1; i<=pages; i++){
// this opens the next page on browser but the data corresponds to page 1
var doc = window.open(page + i,"_top").document;
var table = $(doc).find("table tbody")[0];
// loops through each row of the table and takes only column 6
$(table).find('tr').each( function() {
var row = $(this).find('td');
arr.push($(row[6]).text());
});
}
// do something with arr, but it only contains page=1 data repeated 13 times.