开了个网店,
要从阿里巴巴进货,顺便从进货商的商品介绍上把图片保存到我自己的店里用,
阿里巴巴图片不让存。。
虽然可以看源代码的方式找到图片地址然后保存,但是这样太累,
做个小工具:
用的是aauto这个语言,前两天刚看到的这么个语言,语法简单灵活,做个小软件正合适,
思路很简单,如下:
第一步,加载商品页面:(因为阿里巴巴这个页面是随着滚动条的位置才加载内容的,所以加载后需要滚动到页面底部)
var wb1 = web.form(static,,); wb1.go(url); wb1.wait(); //页面上使用了lazyload,所以必须滚动到底部,才能加载到内容 var scrollScript="self.scroll(0,65000);"; wb1.doScript(scrollScript); win.delay(500); wb1.document.documentElement.scrollTop=65000;
第二步,找到图片地址
//预览图 qEle =wb1.waitQueryEles(id="dt-tab"); var photocontainer = qEle[1].innerHTML; //console.log( photocontainer ); regex = string.regex('"original":"(.*?)"}') ; regex.global = 1; regex.ignoreCase = 1; for i,regex_match in regex.gmatch(photocontainer){ table.push(imgTable,regex_match.SubMatches(0)); } //内容图 qEle = wb1.waitQueryEles( className= "de-description-detail"); var content= qEle[1].innerHTML; regex = string.regex('<img.+?src=\"([^\"]*?)\".*?>') ; regex.global = 1; regex.ignoreCase = 1; for i,regex_match in regex.gmatch(content){ //console.log( ( regex_match.SubMatches(0) ) ); table.push(imgTable,regex_match.SubMatches(0)); }
第三步,下载图片
src=http1.get(fileurl);
string.save(newDir+"\商品图片_"+filename ,src);
完成,图片轻松的下载下来了
以上。