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

[问题求助] VBS如何用正则提取网址中的这一句?

[复制链接]
发表于 2013-5-27 15:37:58 | 显示全部楼层 |阅读模式
  1. set regex = New RegExp
  2. set fso = CreateObject("scripting.filesystemobject")
  3. Set http = CreateObject("Msxml2.XMLHTTP")
  4. url = "http://www.xiami.com/search/album?key=%E6%B5%AE%E8%BA%81"

  5. http.open "GET",url,False
  6. http.send
  7. html = http.responseText

  8. regex.ignoreCase = true
  9. regex.Global = true
  10. regex.Pattern = """浮躁"""
  11. Set matches = regex.Execute(html)
  12. For Each match In matches
  13.         msgbox match
  14. Next
复制代码
我想的是先用title="浮躁"及title="王菲"提取到这一段
  1.                 <div class="album_item100_block">
  2.                         <p class="cover"><a class="CDcover100" href="/album/11943" title="浮躁">
  3.                         <img src="http://img.xiami.com/images/album/img77/2177/119431362392699_1.jpg" width="100" height="100" alt="" /></a>               
  4.                                                 </p>
  5.                         <p class="name"><a href="/album/11943" title="浮躁"><b class="key_red">浮躁</b></a>
  6.                         <a class="singer" href="/artist/2177" title="王菲">王菲</a>
  7.                         </p>
  8.                         <p class="album_rank clearfix"><span style="width:48.5px;">总体评分</span><em>9.7</em></p>
  9.                         <p class="year">1996-08</p>
  10.                 </div>
复制代码
然后再提取: "http://img.xiami.com/images/album/img77/2177/119431362392699_1.jpg",我想保证精度,因为另一个人也有可能有"浮躁"专辑。
发表于 2013-5-27 22:21:21 | 显示全部楼层
  1. Set http = CreateObject("Msxml2.XMLHTTP")
  2. url = "http://www.xiami.com/search/album?key=%E6%B5%AE%E8%BA%81"

  3. http.open "GET",url,False
  4. http.send()
  5. Do Until http.ReadyState = 4 :Wscript.Sleep 100 :Loop
  6. html = http.responseText
  7. Set http = Nothing

  8. With New RegExp
  9.     .Global = true
  10.     .ignoreCase = true
  11.     .Pattern = "title=""浮躁""(.*\r\n){4}.*title=""王菲"""
  12.     For Each match In .Execute(html)
  13.         MsgBox Split(Split(match,vbCrLf)(1),Chr(34))(1)
  14.     Next
  15. End With
复制代码
发表于 2013-5-31 19:09:25 | 显示全部楼层
貌似也可以这样:
  1. Set http = CreateObject("Msxml2.XMLHTTP")
  2. url = "http://www.xiami.com/search/album?key=%E6%B5%AE%E8%BA%81"

  3. http.open "GET",url,False
  4. http.send()
  5. Do Until http.ReadyState = 4 :Wscript.Sleep 100 :Loop
  6. html = http.responseText
  7. Set http = Nothing

  8. Set re = New RegExp
  9. re.Global = true
  10. re.ignoreCase = true
  11. re.Pattern = "title=""浮躁""[\s\S]*?(http://.*?\.jpg)[\s\S]*?title=""王菲"""
  12. For Each match In re.Execute(html)
  13.       MsgBox match.SubMatches(0)
  14. Next
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-17 13:54 , Processed in 0.021528 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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