大模型网页版内容聚合工具:一键获取多个AI助手的回答
大模型网页版内容聚合工具:一键获取多个AI助手的回答
你是否曾经为了同一个问题,要分别打开Kimi、DeepSeek、通义千问等好几个AI助手,复制粘贴它们的回答?本教程将教你如何用Python脚本,自动打开这些AI平台,输入你的问题,等待它们生成回答,最后把所有回答保存成Markdown文件。整个过程只需要运行一次脚本,就能拿到所有结果。
背景:为什么需要聚合AI平台的搜索结果?
目前市面上的大模型AI助手各有千秋:有的擅长逻辑推理,有的创意丰富,有的回答更贴近中文习惯。如果你想全面了解某个问题的答案,往往需要分别询问多个AI。手动操作不仅费时,还容易漏掉重要信息。因此,我们开发了一个自动化工具,能够:
- 同时向多个AI平台提问
- 自动等待每个平台生成完整回答
- 提取回答内容并保存为Markdown文件
- 最后用Claude(另一个AI)将这些回答整合成一份总结报告
这样,你就能高效地获得多方观点,节省大量时间。
操作步骤
第一步:下载并配置Chrome浏览器专用驱动
我们的脚本需要模拟真实用户操作浏览器。Selenium是一个自动化测试工具,可以控制Chrome完成点击、输入等动作。要让Selenium控制Chrome,需要两个组件:
- Chrome浏览器本身(用于显示页面)
- ChromeDriver(相当于“遥控器”,通过它向Chrome发送指令)
请下载以下两个压缩包(版本号可能更新,但这里使用的是Chrome 147.0.7727.50):
# ChromeDriver(遥控器)
https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.50/win64/chromedriver-win64.zip
# Chrome浏览器(无界面也可,但这里我们使用完整版)
https://storage.googleapis.com/chrome-for-testing-public/147.0.7727.50/win64/chrome-win64.zip
下载后解压到本地文件夹。关键操作:将chromedriver.exe所在的目录添加到系统的PATH环境变量中。这样,任何命令行窗口都能直接调用chromedriver。如果你不熟悉环境变量配置,可以搜索“如何添加PATH环境变量”。
第二步:以调试模式启动Chrome
为了让Python脚本连接到一个已经打开的Chrome窗口(而不是每次新开一个),我们需要用“远程调试”模式启动Chrome。这样,脚本就可以通过9222端口与浏览器对话,保持你已登录的会话状态(避免重复登录)。
打开命令行(CMD或PowerShell),进入你解压后的chrome-win64文件夹,运行:
chrome.exe --remote-debugging-port=9222
执行后,会弹出一个新的Chrome窗口。请保持这个窗口一直开着,不要关闭。
第三步:依次打开AI平台链接并手动登录
由于各大AI平台都需要登录账号,而自动登录涉及验证码等复杂问题,我们采用半自动方式:你用浏览器手动登录一次,后续脚本就能复用这个已登录状态。
在刚才启动的Chrome窗口中,依次打开下面每个链接,用手机号或邮箱登录:
| 供应商 | 链接 |
|---|---|
| Kimi (月之暗面) | https://www.kimi.com/ |
| deepseek | https://chat.deepseek.com/a/chat |
| 通义千问 (阿里) | https://www.qianwen.com/ |
| 豆包 (字节跳动) | https://www.doubao.com/chat |
| 腾讯元宝 | https://yuanbao.tencent.com/chat/naQivTmsDa |
小贴士:登录后最好保持每个页面都处于空白聊天状态(没有历史消息干扰)。登录一次就够了,以后只要不关闭这个调试模式的Chrome窗口,下次运行脚本时无需再登录。
第四步:运行聚合脚本(Python)
这是整个工具的核心。你需要安装Python环境(建议3.8以上),然后安装依赖库:
pip install selenium html2text
- selenium:负责控制浏览器
- html2text:把网页中的HTML内容转换成Markdown格式
将下面的完整脚本保存为一个文件,比如ai_aggregator.py。脚本中已经配置好了每个平台的输入框、发送按钮、等待回答完成的方式等。
"""
多平台AI热点搜索工具
聚合多个AI平台的搜索结果,生成markdown文件
"""
import time
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import TimeoutException
import html2text
# ============== 公共工具函数 ==============
def get_driver():
"""创建Chrome驱动,连接到已打开的浏览器"""
options = Options()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
return webdriver.Chrome(options=options)
def html_to_markdown(inner_html):
"""将HTML转换为markdown格式"""
converter = html2text.HTML2Text()
converter.ignore_links = False
converter.ignore_images = False
converter.body_width = 0
return converter.handle(inner_html)
def extract_content(driver, content_xpath):
"""提取页面中的内容并转换为markdown"""
contents = driver.find_elements(By.XPATH, content_xpath)
final_content = ""
for content in contents:
inner_html = content.get_attribute("outerHTML")
markdown_text = html_to_markdown(inner_html)
if len(markdown_text) > len(final_content):
final_content = markdown_text
return final_content
def wait_for_response(driver, wait_selector, wait_xpath=None):
"""等待响应完成"""
time.sleep(2)
wait_long = WebDriverWait(driver, 60 * 10)
if wait_selector == "class":
wait_long.until(lambda d: "stop" not in d.find_element(By.CSS_SELECTOR, wait_xpath).get_attribute("class"))
elif wait_selector == "xpath":
wait_long.until(EC.presence_of_element_located((By.XPATH, wait_xpath)))
elif wait_selector == "invisible":
wait_long.until(EC.invisibility_of_element_located((By.XPATH, wait_xpath)))
elif wait_selector == "disabled":
wait_long.until(EC.presence_of_element_located((By.XPATH, wait_xpath)))
def click_send_button(driver, send_selector, send_value):
"""点击发送按钮"""
if send_selector == "xpath":
snd_element = driver.find_element(By.XPATH, send_value)
else:
snd_element = driver.find_element(By.CSS_SELECTOR, send_value)
ActionChains(driver).move_to_element(snd_element).click().perform()
# ============== 平台配置 ==============
PLATFORMS = {
"deepseek": {
"url": "https://chat.deepseek.com/a/chat",
"input_xpath": "//textarea[@placeholder='给 DeepSeek 发送消息 ']",
"send_method": "enter", # 使用回车发送
"wait_selector": "disabled",
"wait_xpath": "//div[contains(@class, 'ds-icon-button--disabled')]",
"content_xpath": "//div[@class='ds-markdown']",
"output_file": "deepseek.md"
},
"doubao": {
"url": "https://www.doubao.com/chat",
"input_xpath": "//textarea[@placeholder='发消息...']",
"send_selector": "xpath",
"send_value": "//button[@data-testid='chat_input_send_button']",
"wait_selector": "xpath",
"wait_xpath": "//div[@data-state='inactive']",
"content_xpath": "//div[@data-testid='message_text_content']",
"output_file": "doubao.md"
},
"kimi": {
"url": "https://www.kimi.com/",
"input_xpath": "//div[@class='chat-input-editor']",
"input_click_xpath": "//div[@class='chat-input-placeholder']",
"send_selector": "css",
"send_value": "div.send-button-container",
"wait_selector": "class",
"wait_xpath": ".send-button-container",
"content_xpath": "//div[@class='segment-content']",
"output_file": "kimi.md"
},
"qianwen": {
"url": "https://www.qianwen.com/",
"input_xpath": "//div[@data-placeholder='向千问提问']",
"send_selector": "xpath",
"send_value": "//button[@aria-label='发送消息']",
"wait_selector": "invisible",
"wait_xpath": "//button[@aria-label='停止回答']",
"content_xpath": "//div[@class='markdown-pc-special-class']",
"output_file": "qianwen.md"
},
"yuanbao": {
"url": "https://yuanbao.tencent.com/chat/naQivTmsDa",
"input_xpath": "//div[@data-placeholder='有问题,尽管问,shift+enter换行']",
"send_selector": "xpath",
"send_value": "//a[@id='yuanbao-send-btn']",
"wait_selector": "xpath",
"wait_xpath": "//a[@id='yuanbao-send-btn']",
"content_xpath": "//div[@class='hyc-content-md hyc-content-md-done']",
"output_file": "yuanbao.md"
}
}
# ============== 核心实现 ==============
def search_platform(platform_name, query, max_retries=3):
"""搜索单个平台,支持重试机制"""
config = PLATFORMS.get(platform_name)
if not config:
print(f"未知平台: {platform_name}")
return False
output_file = config["output_file"]
for attempt in range(1, max_retries + 1):
print(f"[{platform_name}] 第{attempt}次尝试...")
try:
driver = get_driver()
wait = WebDriverWait(driver, 10)
driver.get(config["url"])
# 点击输入框(部分平台需要)
if "input_click_xpath" in config:
placeholder = wait.until(EC.element_to_be_clickable((By.XPATH, config["input_click_xpath"])))
ActionChains(driver).move_to_element(placeholder).click().perform()
# 输入查询内容
input_box = wait.until(EC.presence_of_element_located((By.XPATH, config["input_xpath"])))
input_box.send_keys(query)
# 发送内容
send_method = config.get("send_method", "click")
if send_method == "enter":
from selenium.webdriver.common.keys import Keys
ActionChains(driver).send_keys(Keys.ENTER).perform()
else:
click_send_button(driver, config["send_selector"], config["send_value"])
# 等待响应
wait_for_response(driver, config["wait_selector"], config.get("wait_xpath"))
# 提取内容
final_content = extract_content(driver, config["content_xpath"])
# 保存文件
if final_content:
with open(output_file, "w", encoding="utf-8") as f:
f.write(final_content)
print(f"[{platform_name}] 成功保存到 {output_file}")
driver.quit()
return True
else:
print(f"[{platform_name}] 未获取到内容")
except TimeoutException:
print(f"[{platform_name}] 超时")
except Exception as e:
print(f"[{platform_name}] 错误: {e}")
finally:
try:
driver.quit()
except:
pass
# 检查文件是否生成
if os.path.exists(output_file) and os.path.getsize(output_file) > 0:
print(f"[{platform_name}] 文件已生成")
return True
# 重试前等待
if attempt < max_retries:
print(f"[{platform_name}] 等待2秒后重试...")
time.sleep(2)
print(f"[{platform_name}] 达到最大重试次数({max_retries}),仍未成功")
return False
def main(query="获取近一周AI咨询", platforms=None):
"""主函数"""
if platforms is None:
platforms = ["deepseek", "doubao", "kimi", "qianwen", "yuanbao"]
results = {}
for platform in platforms:
print(f"\n{'='*20} 正在搜索 {platform} {'='*20}")
results[platform] = search_platform(platform, query)
time.sleep(1) # 平台间间隔
# 打印结果汇总
print(f"\n{'='*20} 搜索结果汇总 {'='*20}")
for platform, success in results.items():
status = "成功" if success else "失败"
print(f"{platform}: {status}")
return results
if __name__ == "__main__":
# 你可以修改这里的query为你感兴趣的问题
query = "获取近一周AI咨询"
main(query)
如何运行?
确保之前的调试Chrome窗口仍然打开,然后在命令行执行:
python ai_aggregator.py
脚本会自动依次访问每个平台,输入你预设的问题(示例中是“获取近一周AI咨询”),等待回答,然后保存为单独的Markdown文件,如deepseek.md、doubao.md等。
第五步:用Claude汇总所有回答
现在你有了多个Markdown文件,每个文件是一个AI的回答。如果你想得到一份综合报告,可以使用Claude(另一个大模型)来整合它们。
假设你已经安装了claude命令行工具(或者你可以直接复制粘贴内容到Claude网页版),运行:
claude --dangerously-skip-permissions --output-format json -p "整合当前目录下的markdown文件,输出summary.md"
这条命令的意思是:让Claude读取当前文件夹下所有.md文件,分析它们的内容,然后生成一份总结报告summary.md。--dangerously-skip-permissions是跳过权限确认(仅在可信环境使用),-p后面是提示词。
如果你没有claude命令行工具,也可以手动将所有.md文件的内容复制到Claude网页版,并说:“请帮我总结这些AI回答,输出一个综合报告”。
常见问题与注意事项
-
为什么脚本会报错“找不到Chrome”?
请检查你是否以调试模式启动了Chrome,并且端口是9222。也可以尝试在脚本中指定Chrome路径。 -
为什么某个平台总是超时?
可能是网页结构发生了变化(AI平台经常更新界面)。你需要打开浏览器的开发者工具(F12),重新查找输入框、发送按钮、回答内容的XPath,并更新脚本中的配置。 -
可以不手动登录吗?
理论上可以,但需要处理验证码、短信等复杂问题。本教程采用半自动方式,更稳定可靠。 -
脚本能同时运行多个平台吗?
不能,因为需要共用一个Chrome窗口。脚本是顺序执行的,一个完成后再处理下一个。 -
如果我想问不同的问题怎么办?
修改脚本最后一行query变量的值,或者通过命令行参数传递(需要稍微修改脚本)。
总结
通过这个工具,你可以:
- 自动化收集多个AI助手的回答
- 标准化输出为Markdown格式,方便阅读和存档
- 集成最终用Claude生成综合报告
整个过程只需要你手动登录一次,之后就可以反复运行脚本,快速获取多方观点。希望这个教程对你有所帮助,你也可以根据自己的需求修改脚本,适配更多AI平台。
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐

所有评论(0)