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

如何用Selenium IDE提取网页文本并保存到本地文本文档?

用Selenium IDE提取指定区域文本/HTML并保存

提取可读文本并保存到文本文档

  • 定位右侧灰色区域元素:根据页面实际结构,用CSS选择器或XPath精准定位该区域(比如区域有唯一类名gray-sidebar,则Target填css=.gray-sidebar;有唯一ID则填css=#summary-region,无标识的话可通过层级写XPath,比如//div[contains(@style,'background-color: gray')])
  • 添加storeText命令:
    • Target:填入上述定位表达式
    • Value:设置变量名,比如summaryContent
  • 添加executeScript命令实现自动保存:
    • Command:executeScript
    • Target:
      const content = arguments[0];
      const blob = new Blob([content], {type: 'text/plain'});
      const downloadLink = document.createElement('a');
      downloadLink.href = URL.createObjectURL(blob);
      downloadLink.download = 'summary_text.txt';
      downloadLink.click();
      URL.revokeObjectURL(downloadLink.href);
      
    • Value:${summaryContent}

提取区域HTML代码并保存

  • 定位右侧灰色区域元素:使用和上面一致的定位表达式
  • 添加storeAttribute命令提取HTML:
    • Target:填入定位表达式
    • Value:设置变量名,比如summaryHtml
    • Attribute:outerHTML
  • 添加executeScript命令保存HTML:
    • Command:executeScript
    • Target:
      const htmlContent = arguments[0];
      const blob = new Blob([htmlContent], {type: 'text/html'});
      const downloadLink = document.createElement('a');
      downloadLink.href = URL.createObjectURL(blob);
      downloadLink.download = 'summary_html.txt';
      downloadLink.click();
      URL.revokeObjectURL(downloadLink.href);
      
    • Value:${summaryHtml}

注意事项

  • 定位表达式需根据页面真实结构调整,确保能准确选中目标灰色区域
  • 如果executeScript无反应,可先通过echo命令(Target填${summaryContent}或${summaryHtml})验证变量是否获取到内容,再手动复制保存

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 17:42:08