Skip to content

Commit

Permalink
fix: loginbutton作用域问题
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed Aug 7, 2024
1 parent ba801c9 commit 1f626aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#支持多账户,使用逗号分隔每个账户,密码中有特殊字符可能会导致识别失败
USERNAMES=hahaha2,hahaha1,ha1,ha2,DrKBoogieWoogie,lsp,lsb #888存在问题
PASSWORDS="BfdSGt}F4!5pLHt,BfdSGt}F4!5pLHt,iTs9Wx4+3Eavkhk,W$RhQUVn5E?BBBq,]\"w%2Qd%M8Z6-SS,HU5B6Ee]kRB%Qj',uYE)46Ej8phu$#u" # 密码外面要加上双引号,密码内部如果有双引号需要加上转义字符 反斜杠 \
WEBSITE=https://linux.do
WEBSITE=https://linux.do

# 需要阅读的网站,支持后面那些:https://meta.discourse.org, https://meta.appinn.net/, https://community.openai.com/
# 需要阅读的网站,支持后面那些:https://meta.discourse.org, https://meta.appinn.net, https://community.openai.com
ENVIRONMENT=production
43 changes: 23 additions & 20 deletions bypasscf.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,32 +185,35 @@ async function launchBrowserForUser(username, password) {
}
async function login(page, username, password) {
// 使用XPath查询找到包含"登录"或"login"文本的按钮
let loginButton;
await page.evaluate(() => {
let loginButton = Array.from(document.querySelectorAll("button")).find(
(button) =>
button.textContent.includes("登录") ||
button.textContent.includes("login")
);
// 如果没有找到,尝试根据类名查找
if (!loginButton) {
loginButton = document.querySelector(".login-button");
}
if (loginButton) {
loginButton.click();
console.log("Login button clicked.");
} else {
console.log("Login button not found.");
}
});
if (!loginButton) {
let loginButtonFound = await page.evaluate(() => {
let loginButton = Array.from(document.querySelectorAll("button")).find(
(button) =>
button.textContent.includes("登录") ||
button.textContent.includes("login")
); // 注意loginButton 变量在外部作用域中是无法被 page.evaluate 内部的代码直接修改的。page.evaluate 的代码是在浏览器环境中执行的,这意味着它们无法直接影响 Node.js 环境中的变量
// 如果没有找到,尝试根据类名查找
if (!loginButton) {
loginButton = document.querySelector(".login-button");
}
if (loginButton) {
loginButton.click();
console.log("Login button clicked.");
return true; // 返回true表示找到了按钮并点击了
} else {
console.log("Login button not found.");
return false; // 返回false表示没有找到按钮
}
});
if (!loginButtonFound) {
if (loginUrl == "https://meta.appinn.net") {
await page.goto("https://meta.appinn.net/t/topic/52006", {
waitUntil: "domcontentloaded",
});
await page.click(".discourse-reactions-reaction-button");
} else {
await page.goto(`${loginUrl}/t/topic/1`, { waitUntil: "domcontentloaded" });
await page.goto(`${loginUrl}/t/topic/1`, {
waitUntil: "domcontentloaded",
});
await page.click(".discourse-reactions-reaction-button");
}
}
Expand Down

0 comments on commit 1f626aa

Please sign in to comment.