@@ -176,53 +176,20 @@ export const reverseImageSearch = {
176176 const tagA = singleItem . getElementsByTagName ( "a" ) ;
177177 singleResult . sourceUrl = tagA [ 0 ] . getAttribute ( "href" ) ;
178178 singleResult . title = tagA [ 0 ] . innerText ;
179- // console.log(tagA.length);
180- // console.log(tagA[0]);
181- // console.log(tagA[1]);
182- // console.log(tagA[2]);
183- // console.log(tagA[3]);
184- // console.log(tagA[4]);
185- // console.log("----------");
186- if ( tagA [ 4 ] ) {
187- let link = tagA [ 4 ] . getAttribute ( "href" ) ;
188- link = parseGoogleImageLink ( link ) ;
189- singleResult . imageUrl = link ;
190- singleResult . thumbUrl = link ;
179+ //new method to dig the image Source
180+ for ( let i = 2 ; i < tagA . length ; i ++ ) {
181+ if ( tagA [ i ] ) {
182+ let link = tagA [ i ] . getAttribute ( "href" ) ;
183+ //console.log(tagA[i]);
184+ link = parseGoogleImageLink ( link ) ;
185+ if ( link ) {
186+ console . log ( link ) ;
187+ singleResult . imageUrl = link ;
188+ singleResult . thumbUrl = link ;
189+ break ;
190+ }
191+ }
191192 }
192- //console.log({a:tagA[1],b:tagA[2],c:tagA[3],d:tagA[0]});
193- //console.log(tagA[1]);
194- //console.log(tagA[2]);
195- //console.log(singleResult.sourceUrl );
196- //console.log(tagA.length);
197- // let test = tagA[2].getAttribute("href");
198- // console.log(test);
199- // console.log(parseGoogleImageLink(test));
200- //let link = tagA[1].getAttribute("href");
201-
202- //singleResult.imageUrl = link.substring(link.indexOf("=") + 1, link.indexOf("&imgre"));
203- //console.log(singleResult.imageUrl);
204-
205- // // if (!singleResult.imageUrl) {
206- // // let tempImgLink = tagA[3].getAttribute("href");
207- // // //console.log('----------------');
208- // // //console.log(tempImgLink);
209- // // tempImgLink = tempImgLink.substr(tempImgLink.indexOf("imgurl=") + "imgurl=".length);
210- // // tempImgLink = tempImgLink.substr(0, tempImgLink.indexOf("&"));
211- // // //console.log(tempImgLink);
212- // // if (tempImgLink.match(/\:s$/)) {
213- // // tempImgLink = tempImgLink.substr(0, tempImgLink.length - 2);
214- // // console.log(tempImgLink);
215- // // }
216- // // else if(tempImgLink.indexOf("%3") !== -1) {
217- // // tempImgLink = tempImgLink.substr(0, tempImgLink.indexOf("%3"));
218- // // //console.log(tempImgLink);
219- // // }
220- // // singleResult.imageUrl = tempImgLink;
221- // // }
222- // singleResult.thumbUrl = singleResult.imageUrl;
223- //process description
224- //class st span contain N child, first child is size info
225- //behind children are description,conbine them
226193 const tagSpan = singleItem . getElementsByClassName ( "st" ) [ 0 ] . childNodes ;
227194 let description = "" ;
228195 for ( let i = 0 ; i < tagSpan . length ; i ++ ) {
0 commit comments