找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 16199|回复: 1

[问题求助] [已解决]VBS如何利用正则表达式获取网页源代码中的内容输出到txt

[复制链接]
发表于 2017-5-17 13:39:32 | 显示全部楼层 |阅读模式
本帖最后由 WindCat 于 2017-5-17 20:48 编辑

因为会不定期改动
所以我想做一个读取网页的中的地址然后修改系统pac的小工具
结合计划任务达到定期自动修改的目的
代码是从网上搜来改的
  1. url="https://freepac.co/"
  2. Set html = CreateObject("microsoft.xmlhttp")
  3. html.open "GET",url,False
  4. html.send
  5. s=html.responseText
  6. 'MsgBox s

  7. Set re=New RegExp
  8. re.Global=True
  9. re.Pattern="free.upac.pro/([0-9,a-z]*)"
  10. re.IgnoreCase=True
  11. Set matchs=re.Execute (s)
  12. output=""
  13. For Each m In matchs
  14.     output=output & m.Submatches(0) & vbCrLf
  15. Next
  16. MsgBox output
复制代码
现在我遇到了一个蠢问题...
虽然知道输出是SaveToFile
但是不知如何修改才能让它输出Pattern的值到1.txt
然后用bat命令读取1.txt的值修改注册表以应用
  1. reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v AutoConfigURL /d "https://free.upac.pro/%%a" /f
复制代码
发表于 2017-5-17 19:10:09 | 显示全部楼层
  1. Option Explicit

  2. Dim wso, http, url, html, re, matchs, m, s
  3. Set wso = CreateObject("WScript.Shell")
  4. Set http = CreateObject("microsoft.xmlhttp")

  5. '获取url网页内容
  6. url = "https://freepac.co/"
  7. http.open "GET", url, False
  8. http.send
  9. html = http.responseText

  10. '提取网页中的字符串
  11. Set re = New RegExp
  12. re.Global = True
  13. re.Pattern = "free.upac.pro/([0-9,a-z]*)"
  14. re.IgnoreCase = True
  15. Set matchs = re.Execute(html)
  16. If matchs.Count > 0 Then
  17.         s = matchs.Item(0).Submatches(0)        '提取第一个匹配项
  18.         '写入注册表
  19.         wso.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\AutoConfigURL", url & s, "REG_SZ"
  20. End If

  21. '打开IE代理设定界面
  22. wso.Run "control inetcpl.cpl,,4", 1, False
  23. wso.AppActivate "internet"
  24. WScript.Sleep 500
  25. wso.Sendkeys "%L"
复制代码

评分

参与人数 1技术 +1 收起 理由
WindCat + 1 非常感谢!请问有什么推荐的入门教学吗?我 ...

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 07:43 , Processed in 0.070497 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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