我正在尝试制作一个用于删除我的instagram图片的小机器人,并为此编写代码。实际上,桌面版instagram没有删除图片选项。但是,当您将用户代理更改为移动电话时,您可以。
我使用Google Dev Console尝试了代码。如果您一一编写代码就可以了。但是当我将其设为函数时,会出现此错误。 Cannot read property 'click'
var username = prompt("Please enter your instagram account", "myinstagramacc");
window.location.replace("https://instagram.com/"+username);
function deletePics(){
setTimeout(() => document.getElementsByClassName("_9AhH0")[0].click(), 1000);
setTimeout(() => document.getElementsByTagName("button")[5].click() , 1000);
setTimeout(() => document.getElementsByTagName("button")[7].click() , 1000);
setTimeout(() => document.getElementsByTagName("button")[7].click() , 1000);
}
for(i=0;i<17;i++)
setTimeout(deletePics(),1000);
预期
浏览器将使用我的用户名,然后进入主屏幕并单击图片删除图片,单击三个点图标,然后选择删除,然后选择删除。
实际结果 取得用户名后,进入主屏幕并单击第一张图片,我看到此错误:
Uncaught TypeError: Cannot read property 'click' of undefined
at setTimeout (<anonymous>:3:65)
Uncaught TypeError: Cannot read property 'click' of undefined
at setTimeout (<anonymous>:4:65)
Uncaught TypeError: Cannot read property 'click' of undefined
at setTimeout (<anonymous>:5:65)
答案 0 :(得分:0)
函数调用错误
var username = prompt("Please enter your instagram account", "myinstagramacc");
//window.location.replace("https://instagram.com/"+username);
function deletePics() {
setTimeout(() => document.getElementsByClassName("_9AhH0")[0].click(), 1000);
setTimeout(() => document.getElementsByTagName("button")[5].click(), 1000);
setTimeout(() => document.getElementsByTagName("button")[7].click(), 1000);
setTimeout(() => document.getElementsByTagName("button")[7].click(), 1000);
}
for (i = 0; i < 17; i++)
setTimeout(deletePics, 1000);
<div class="_9AhH0">aa</div>
<button>click</button><button>click</button><button>click</button><button>click</button><button>click</button><button>click</button><button>click</button><button>click</button>