|
6 | 6 | import ajax from 'SRC/utils/ajax.js'; |
7 | 7 | import ENGINE_DONE from 'SRC/constant/constants.js'; |
8 | 8 | import { ENGINE_WEIGHTS } from '../constant/constants'; |
| 9 | +import {parseGoogleImageLink} from 'SRC/utils/imageUtils'; |
9 | 10 | const HTML = new DOMParser(); |
10 | 11 | // Data Format |
11 | 12 | export const reverseImageSearch = { |
@@ -168,32 +169,57 @@ export const reverseImageSearch = { |
168 | 169 | weight: ENGINE_WEIGHTS.google - i + Math.random(), |
169 | 170 | } |
170 | 171 | const singleItem = list[i]; |
| 172 | + //console.log(singleItem); |
171 | 173 | //process title,imageUrl,sourceUrl and thumbUrl |
172 | 174 | //first <a> contain title and imageUrl |
173 | 175 | //second <a> contain sourceUrl and thumbUrl |
174 | 176 | const tagA = singleItem.getElementsByTagName("a"); |
175 | 177 | singleResult.sourceUrl = tagA[0].getAttribute("href"); |
176 | 178 | singleResult.title = tagA[0].innerText; |
177 | | - let link = tagA[1].getAttribute("href"); |
178 | | - singleResult.imageUrl = link.substring(link.indexOf("=") + 1, link.indexOf("&imgre")); |
179 | | - if (!singleResult.imageUrl) { |
180 | | - let tempImgLink = tagA[3].getAttribute("href"); |
181 | | - console.log('----------------'); |
182 | | - console.log(tempImgLink); |
183 | | - tempImgLink = tempImgLink.substr(tempImgLink.indexOf("imgurl=") + "imgurl=".length); |
184 | | - tempImgLink = tempImgLink.substr(0, tempImgLink.indexOf("&")); |
185 | | - console.log(tempImgLink); |
186 | | - if (tempImgLink.match(/\:s$/)) { |
187 | | - tempImgLink = tempImgLink.substr(0, tempImgLink.length - 2); |
188 | | - console.log(tempImgLink); |
189 | | - } |
190 | | - else if(tempImgLink.indexOf("%3") !== -1) { |
191 | | - tempImgLink = tempImgLink.substr(0, tempImgLink.indexOf("%3")); |
192 | | - console.log(tempImgLink); |
193 | | - } |
194 | | - singleResult.imageUrl = tempImgLink; |
195 | | - } |
196 | | - singleResult.thumbUrl = singleResult.imageUrl; |
| 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; |
| 191 | + } |
| 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; |
197 | 223 | //process description |
198 | 224 | //class st span contain N child, first child is size info |
199 | 225 | //behind children are description,conbine them |
|
0 commit comments