開了個網店,
要從阿里巴巴進貨,順便從進貨商的商品介紹上把圖片保存到我自己的店里用,
阿里巴巴圖片不讓存。。
雖然可以看源代碼的方式找到圖片地址然后保存,但是這樣太累,
做個小工具:
用的是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);
完成,圖片輕松的下載下來了
以上。