我正在制作一个Facebook群组成员刮刀,并且我发现页面自动加载,当滚动到下来自动解决我使用以下代码: -
setInterval(function(){
$(document).scrollTop($(document).height());
},1000);
它工作正常,但我的其余代码也在同一时间工作。
var main = [];
$('#groupsMemberSection_self_bio').find('.uiList').each(function(){
$(this).find('._6a').each(function(){
$(this).find('div._6a:last').each(function(){
var href = $(this).find('a').attr('href');
if(href != undefined){
var obj = {};
var profile_url = $(this).find('a').attr('href');
var name = $(this).find('a').text();
var company_name_position = $(this).find('._60rj').next().text();
obj['url'] = profile_url;
obj['name'] = name;
obj['company_name'] = company_name_position;
}
if(obj != undefined){
main.push(obj)
}
})
})
});
$('#groupsMemberSection_admins_moderators').find('.uiList').each(function(){
$(this).find('._6a').each(function(){
$(this).find('div._6a:last').each(function(){
var href = $(this).find('a').attr('href');
if(href != undefined){
var obj = {};
var profile_url = $(this).find('a').attr('href');
var name = $(this).find('a').text();
var company_name_position = $(this).find('._60rj').next().text();
obj['url'] = profile_url;
obj['name'] = name;
obj['company_name'] = company_name_position;
}
if(obj != undefined){
main.push(obj)
}
})
})
});
$('#groupsMemberSection_things_in_common').find('.uiList').each(function(){
$(this).find('._6a').each(function(){
$(this).find('div._6a:last').each(function(){
var href = $(this).find('a').attr('href');
if(href != undefined){
var obj = {};
var profile_url = $(this).find('a').attr('href');
var name = $(this).find('a').text();
var company_name_position = $(this).find('._60rj').next().text();
obj['url'] = profile_url;
obj['name'] = name;
obj['company_name'] = company_name_position;
}
if(obj != undefined){
main.push(obj)
}
})
})
});
$('#groupsMemberSection_recently_joined').find('.uiList').each(function(i,v){
$(this).find('._6a').each(function(){
$(this).find('div._6a:last').each(function(){
var href = $(this).find('a').attr('href');
if(href != undefined){
var obj = {};
var profile_url = $(this).find('a').attr('href');
var name = $(this).find('a').text();
var company_name_position = $(this).find('._60rj').next().text();
obj['url'] = profile_url;
obj['name'] = name;
obj['company_name'] = company_name_position;
}
if(obj != undefined){
main.push(obj)
}
})
})
});
console.log('data', main);
downloadCSV('data.csv', main)
function convertArrayOfObjectsToCSV(args) {
var result, ctr, keys, columnDelimiter, lineDelimiter, data;
data = args.data || null;
if (data == null || !data.length) {
return null;
}
columnDelimiter = args.columnDelimiter || ',';
lineDelimiter = args.lineDelimiter || '\n';
keys = Object.keys(data[0]);
result = '';
result += keys.join(columnDelimiter);
result += lineDelimiter;
data.forEach(function(item) {
ctr = 0;
keys.forEach(function(key) {
if (ctr > 0) result += columnDelimiter;
result += item[key];
ctr++;
});
result += lineDelimiter;
});
return result;
}
function downloadCSV(args, stockData) {
var data, filename, link;
var csv = convertArrayOfObjectsToCSV({
data: stockData
});
if (csv == null) return;
filename = args.filename || 'export.csv';
if (!csv.match(/^data:text\/csv/i)) {
csv = 'data:text/csv;charset=utf-8,' + csv;
}
data = encodeURI(csv);
link = document.createElement('a');
link.setAttribute('href', data);
link.setAttribute('download', filename);
link.click();
}
我想要的是csv文件应该只在页面加载完成时下载一次我的意思是设置的分页是自动加载到最后一页请帮助..我可以匹配上面的条件,以便一次最后一次页面到达我的csv根据页面上的数据下载或如果有任何其他方式,那么请帮助