You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求编写浏览器控制台用的页面加载自动点击关注按钮的JavaScript脚本

自动点击Zomato页面所有关注按钮的控制台代码

基础版(点击当前可见的所有按钮)

打开目标页面后,按F12打开浏览器控制台,粘贴以下代码运行即可点击当前页面中所有可见的关注按钮:

// 筛选所有可点击的关注按钮(匹配按钮文本或SVG的aria-label)
const followButtons = Array.from(document.querySelectorAll('button')).filter(button => {
  const buttonText = button.textContent.trim();
  const svgLabel = button.querySelector('svg')?.getAttribute('aria-label');
  return (buttonText === 'Follow' || svgLabel === 'Follow') && !button.disabled;
});

// 遍历点击每个按钮
followButtons.forEach((button, index) => {
  button.click();
  console.log(`已点击第 ${index + 1} 个关注按钮`);
});

进阶版(自动滚动加载并点击所有按钮)

如果页面的关注按钮是滚动加载的(下方按钮需要滚动后才会出现),可以使用以下代码自动滚动页面、加载更多按钮并批量点击:

async function autoFollowAll() {
  const clickedButtons = new Set();
  let isLoading = false;

  while (true) {
    // 筛选未点击过的有效关注按钮
    const currentButtons = Array.from(document.querySelectorAll('button')).filter(button => {
      const buttonText = button.textContent.trim();
      const svgLabel = button.querySelector('svg')?.getAttribute('aria-label');
      return (buttonText === 'Follow' || svgLabel === 'Follow') && !button.disabled && !clickedButtons.has(button);
    });

    if (currentButtons.length === 0) {
      // 检查是否还有更多内容可加载
      const lastScrollHeight = document.body.scrollHeight;
      window.scrollTo(0, lastScrollHeight);
      await new Promise(resolve => setTimeout(resolve, 2000));
      
      if (document.body.scrollHeight === lastScrollHeight) {
        console.log('已完成所有关注按钮的点击,没有更多内容了');
        break;
      }
      continue;
    }

    // 点击当前批次的按钮
    currentButtons.forEach(button => {
      button.click();
      clickedButtons.add(button);
    });
    console.log(`本次点击 ${currentButtons.length} 个按钮,累计点击 ${clickedButtons.size} 个`);

    // 滚动页面加载更多
    window.scrollTo(0, document.body.scrollHeight);
    await new Promise(resolve => setTimeout(resolve, 2000));
  }
}

// 执行自动点击
autoFollowAll();

注意事项

  • 网站可能会有反机器人机制,频繁批量点击可能导致账号暂时受限,建议适当延长代码中的等待时间(修改setTimeout的毫秒数)。
  • 如果代码失效,大概率是网站更新了页面元素的结构,此时需要右键点击关注按钮,选择“检查”查看元素的新属性/类名,替换代码中的筛选条件。

内容的提问来源于stack exchange,提问作者Priya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 00:03:33