[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

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

本帖最后由 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
复制代码

  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

评分人数

    • WindCat: 非常感谢!请问有什么推荐的入门教学吗?我 ...技术 + 1
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

返回列表