ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 565|回复: 11

[分享] jsa自定义函数获取网页数据

[复制链接]

TA的精华主题

TA的得分主题

发表于 2024-1-14 15:48 | 显示全部楼层 |阅读模式
{E53DC374-13C0-4ac2-95E8-08EAE90B87D1}.png
截图20240114153813.png

代码如下:
  1. function Workbook_Open(){
  2.         Application.MacroOptions("JSAWEBSERVICE","从Internet或Intranet上的Web服务返回数据。",undefined,undefined,undefined,undefined,14,undefined,undefined,undefined,["要调用的Web服务的URL","设置请求头"])
  3.         Application.MacroOptions("JSAFILTERXML","从XML内容返回数组、位置、值。",undefined,undefined,undefined,undefined,14,undefined,undefined,undefined,[
  4.                 "有效XML格式的字符串。",
  5.                 "返回类型。\n\n1:返回数组;\n2:返回所需值在数组中的位置,需参数searchvalue_index_qms;\n3:返回所需值,需参数searchvalue_index_qms;\n4:返回包含所需值数组,需参数searchvalue_index_qms、hms;\n5:返回所需值,需参数searchvalue_index_qms、hms、index。",
  6.                 "所需值、位置、前面是。\n\nreturntypeof为2,为所需值;\nreturntypeof为3,为位置;\nreturntypeof为4,为前面是。",
  7.                 "后面是。",
  8.                 "位置。"
  9.         ])
  10. }

  11. function JSAWEBSERVICE(url,referer){
  12.         var obj = new XMLHttpRequest()
  13.         obj.open("GET",url,false)
  14.         obj.setRequestHeader("Referer",referer)
  15.         obj.send()
  16.         return obj.responseText
  17. }

  18. function JSAFILTERXML(xml,returntypeof,searchvalue_index_qms,hms,index){
  19.         var arry = xml.split(/<[^<>]+>/g)
  20.        
  21.         if(returntypeof == 1){return arry} //返回数组。
  22.        
  23.         if(returntypeof == 2){return [...arry.entries()].filter(v=>v[1].includes(searchvalue_index_qms))} //返回所需值在数组中的位置,需参数searchvalue_index_qms。
  24.         if(returntypeof == 3){return arry[searchvalue_index_qms]} //返回所需值,需参数searchvalue_index_qms。
  25.        
  26.         if(returntypeof == 4){ //返回包含所需值数组,需参数searchvalue_index_qms、hms。
  27.                 var pphb = []
  28.                 arry.forEach(v=>{
  29.                         var reg = RegExp("(?<=" + searchvalue_index_qms + ")" + ".*?" + "(?=" + hms + ")","gs")
  30.                         var ppsz = v.match(reg)
  31.                         if(ppsz != null){pphb = pphb.concat(ppsz)}
  32.                 })
  33.                 return [...pphb.entries()]
  34.         }
  35.         if(returntypeof == 5){ //返回所需值,需参数searchvalue_index_qms、hms、index。
  36.                 var pphb = []
  37.                 arry.forEach(v=>{
  38.                         var reg = RegExp("(?<=" + searchvalue_index_qms + ")" + ".*?" + "(?=" + hms + ")","gs")
  39.                         var ppsz = v.match(reg)
  40.                         if(ppsz != null){pphb = pphb.concat(ppsz)}
  41.                 })
  42.                 return pphb[index]
  43.         }
  44. }
复制代码




评分

1

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2024-1-14 15:55 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2024-1-14 16:24 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
学习了!!

TA的精华主题

TA的得分主题

发表于 2024-1-14 17:51 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2024-1-15 14:30 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
用“fetch”能否替换掉“XMLHttpRequest”?

TA的精华主题

TA的得分主题

发表于 2024-2-14 00:08 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
感谢分享&#160;,能否多发几个网抓好实例!

TA的精华主题

TA的得分主题

发表于 2024-2-29 07:53 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2024-3-2 23:01 | 显示全部楼层
中华美德 发表于 2024-2-29 07:53
请老师解答一下这个贴:https://club.excelhome.net/thread-1685192-1-1.html?_dsign=a73b8b4c

我看看,试解一下

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2024-3-9 10:16 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2024-3-30 09:56 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-27 18:49 , Processed in 0.041057 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表