标题: 用VBS下载国家地理每日一图
作者: Demon
链接: https://demon.tw/my-work/vbs-photo-of-the-day.html
版权: 本博客的所有文章,都遵守“署名-非商业性使用-相同方式共享 2.5 中国大陆”协议条款。
国家地理的每日一图栏目很不错,常有一些精彩的照片。
写个VBS脚本下载之并重命名为日期加上照片标题。
都是正则表达式,而且没有写注释的习惯,很乱。
赞赏Option Explicit Const url = "http://photography.nationalgeographic.com/" &_ "photography/photo-of-the-day/" Dim http, ado Dim html, image_url, image_name, image_time Dim regex, matches, match Set http = CreateObject("Msxml2.XMLHTTP") Set ado = CreateObject("Adodb.Stream") Set regex = New RegExp http.open "GET",url,False http.send html = http.responseText regex.Global = True regex.Pattern = "<div class=""primary_photo"">([\s\S]+?)</div>" Set matches = regex.Execute(html) For Each match In matches image_url = match.Submatches(0) Next regex.Pattern = "<img src=""(.+?)"" [\s\S]+>" Set matches = regex.Execute(image_url) For Each match In matches image_url = match.Submatches(0) Next regex.Pattern = "<h1>(.+)</h1>" Set matches = regex.Execute(html) For Each match In matches image_name = match.Submatches(0) Next regex.Pattern = "<.+?>" Set matches = regex.Execute(image_name) For Each match In matches image_name = Replace(image_name, match, "") Next regex.Pattern = "<p class=""publication_time"">(.+?)</p>" Set matches = regex.Execute(html) For Each match In matches image_time = match.Submatches(0) Next http.open "GET",image_url,False http.send ado.Type = 1 ado.Open ado.Write http.responseBody ado.SaveToFile image_time & " " & image_name & ".jpg", 2 ado.Close
微信赞赏支付宝赞赏
随机文章:
……明明就猜对了
奇怪,保存到哪里了?
请教大神,能指定保存目录么?
运行的时候报错: ActiveX 部件不能创建对象: ‘Abodb.Stream’,网上找的解决办法,重新注册scrrun.dll也没有用,请教下这个问题怎么解决?