Skip to content

Instantly share code, notes, and snippets.

@skyzh
Created August 22, 2018 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyzh/8e983861209e455432720b1a2b0b42b7 to your computer and use it in GitHub Desktop.
Save skyzh/8e983861209e455432720b1a2b0b42b7 to your computer and use it in GitHub Desktop.
Simple QQ repeat Bot
const {Builder, By, Key, until} = require('selenium-webdriver');
let processed_text = {};
(async function do_fetch() {
let driver = await new Builder().forBrowser('chrome').build();
try {
await driver.get('http://web2.qq.com');
while(true) {
await driver.wait(until.elementLocated(By.id("panelTitle-5")));
console.log("Title located");
let title = await driver.findElement(By.id("panelTitle-5")).getText();
console.log(`Title found ${title}`);
if (title == "SJTU18级工试新生交流群") {
while(true) {
await driver.wait(until.elementLocated(By.className("chat_content")));
let chats = await driver.findElements(By.className("chat_content"));
try {
for (chat of chats) {
let message = await chat.getText();
let id = await chat.getId();
if (!message.startsWith('+1') && message.trim() != "") {
let textarea = await driver.findElement(By.id("chat_textarea"));
let button = await driver.findElement(By.id("send_chat_btn"));
await driver.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);",
chat, "class", "");
textarea.sendKeys(`+1 ${message}`);
await driver.sleep(200);
await button.click();
console.log(`+1 ${message} sent`);
await driver.sleep(500);
}
}
}
catch (e) {
};
await driver.sleep(500);
}
}
await driver.sleep(3000);
}
} finally {
await driver.quit();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment