当前位置: 首页> 教育> 锐评 > 游戏ui界面设计_最近国内重大新闻事件_排名优化网站seo排名_app拉新推广代理

游戏ui界面设计_最近国内重大新闻事件_排名优化网站seo排名_app拉新推广代理

时间:2025/7/11 8:16:40来源:https://blog.csdn.net/m0_60008263/article/details/146022270 浏览次数:0次
游戏ui界面设计_最近国内重大新闻事件_排名优化网站seo排名_app拉新推广代理

在Bruno环境中我得脚本是这样的 

const parser = require('htmlparser2');
const cssSelect = require('css-select')const {parseDocument} = parser;const dom = parseDocument(res.getBody());const SAMLRequestElement = cssSelect.selectOne("input[name='SAMLRequest']", dom);
if (SAMLRequestElement) {const SAMLRequestValue = SAMLRequestElement.attribs.value;bru.setVar("SAMLRequest", decodeURIComponent(SAMLRequestValue));
} else {console.error("SAMLRequest input element not found");
}const SignatureElement = cssSelect.selectOne("input[name='Signature']", dom);
if (SignatureElement) {const SignatureValue = SignatureElement.attribs.value;bru.setVar("Signature", decodeURIComponent(SignatureValue));
} else {console.log("Signature input element not found");
}const SigAlgElement = cssSelect.selectOne("input[name='SigAlg']", dom);
if (SigAlgElement) {const SigAlgValue = SigAlgElement.attribs.value;bru.setVar("SigAlg", decodeURIComponent(SigAlgValue));
} else {console.error("SigAlg input element not found");
}const RelayState = cssSelect.selectOne("input[name='RelayState']", dom).attribs.value;
bru.setVar("RelayState", RelayState)
console.log("RelayState is " + RelayState);const authenticityToken = cssSelect.selectOne("input[name='authenticity_token']", dom).attribs.value;
bru.setVar("authenticityToken", authenticityToken)const spId = cssSelect.selectOne("input[name='spId']", dom).attribs.value;
bru.setVar("spId", spId)const spName = cssSelect.selectOne("input[name='spName']", dom).attribs.value;
bru.setVar("spName", spName)const idpSSOEndpoint = cssSelect.selectOne("input[name='idpSSOEndpoint']", dom).attribs.value;
bru.setVar("idpSSOEndpoint", idpSSOEndpoint)const xsrfProtection = cssSelect.selectOne("input[name='xsrfProtection']", dom).attribs.value;
bru.setVar("xsrfProtection", xsrfProtection)let cookies = res.getHeader("set-cookie");if (cookies && cookies.length > 0) {let cookieDict = {};cookies.forEach(cookie => {let parts = cookie.split(';'); let [name, value] = parts[0].split('='); name = name.trim();value = value.trim();cookieDict[name] = value;});let cookieString = Object.keys(cookieDict).map(name => {return `${name}=${cookieDict[name]}`;}).join('; ');bru.setVar("cookies", cookieString);console.log("Combined cookie string with latest values:", cookieString);
} else {console.error("No cookies found in the set-cookie header.");
}

由于 Bruno 是一个专注于 API 开发和测试的工具,它的脚本执行环境可能不支持典型的 Node.js 模块加载方式(如使用 require 来加载模块)。因此无法直接在 Bruno 中使用 Node.js 的 htmlparser2css-select。以下是一些可以在不使用 Node.js 模块的情况下,在 Bruno 中实现类似的功能:

1. 使用浏览器原生方法解析 HTML:

Bruno 的脚本环境类似于浏览器环境,可以使用浏览器提供的 API 来解析 HTML。

使用 DOMParser 解析 HTML:
// Assuming `res.getBody()` returns the entire HTML as a string
const parser = new DOMParser();
const doc = parser.parseFromString(res.getBody(), "text/html");// Now you can use traditional DOM methods to find elements
const SAMLRequestElement = doc.querySelector("input[name='SAMLRequest']");
if (SAMLRequestElement) {const SAMLRequestValue = SAMLRequestElement.value;bru.setVar("SAMLRequest", decodeURIComponent(SAMLRequestValue));
} else {console.error("SAMLRequest input element not found");
}// Continue similarly for other elements using `querySelector` or `querySelectorAll`

2. 检查和处理输入元素:

确保在尝试访问属性之前先检查元素是否存在。对于不存在的元素,打印适当的错误信息。

3. 处理 Cookies:

Bruno 脚本中的 Cookie 处理相对正常,因为它依赖于解析字符串来构建 Cookie 字典。确保字符串处理逻辑是正确的,这看起来已经做得很好。

4. 使用 Bruno 提供的 API:

确保您使用的 bru.setVar 在 Bruno 中被正确调用并且可用。可以通过 Bruno 的文档来确认使用方法。

总结:

  • 避免使用无法加载的 Node.js 模块:在 Bruno 中的脚本可能无法使用普通的 Node.js 模块,因此可以依靠原生浏览器 API 来操作 DOM。
  • 确保节点查找逻辑正确无误:使用 querySelectorquerySelectorAll 来定位和操作 HTML 元素。
  • 处理和管理变量:充分利用 bru.setVar 进行变量设置、测试和调试。

可以使用上文中的建议来修改和运行代码。调整后的代码不仅仅解决了模块加载的问题,还与浏览器环境下的原生功能保持一致。

关键字:游戏ui界面设计_最近国内重大新闻事件_排名优化网站seo排名_app拉新推广代理

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: