|
| 1 | +# JavaScript 蜘蛛 |
| 2 | + |
| 3 | +如何使用JavaScript编写蜘蛛,以便从目标网站自动下载一些svg图像! |
| 4 | + |
| 5 | + |
| 6 | +https://gist.github.com/xgqfrms-GitHub/0bf82ff06037a0d1776c9f30033cbfd1 |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +http://www.cnblogs.com/post/readauth?url=/xgqfrms/p/6942147.html |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +https://rollbar.com/docs/ |
| 15 | + |
| 16 | + |
| 17 | +```js |
| 18 | + |
| 19 | +const links = document.querySelectorAll(`ul.image-list a`); |
| 20 | + |
| 21 | +console.log(getComputedStyle(links[0], ':before').getPropertyValue('background-image')); |
| 22 | +// url("https://rollbar.com/assets/shared/logos/ruby-icon.svg") |
| 23 | + |
| 24 | +let img = getComputedStyle(links[0], '::before').getPropertyValue('background-image'); |
| 25 | +// url("https://rollbar.com/assets/shared/logos/ruby-icon.svg") |
| 26 | + |
| 27 | +let newImage= img.replace(/(url\(")|("\))/g,''); |
| 28 | +// "https://rollbar.com/assets/shared/logos/ruby-icon.svg" |
| 29 | + |
| 30 | +console.log(newImage); |
| 31 | +// https://rollbar.com/assets/shared/logos/ruby-icon.svg |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +/* |
| 37 | +add new key to object javascript |
| 38 | +
|
| 39 | +
|
| 40 | +https://stackoverflow.com/questions/1168807/how-can-i-add-a-key-value-pair-to-a-javascript-object |
| 41 | +*/ |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +var a = $("<a>") |
| 51 | + .attr("href", "http://i.stack.imgur.com/L8rHf.png") |
| 52 | + .attr("download", "img.png") |
| 53 | + .appendTo("body"); |
| 54 | + |
| 55 | +a[0].click(); |
| 56 | + |
| 57 | +a.remove(); |
| 58 | +``` |
| 59 | + |
| 60 | + |
| 61 | +```js |
| 62 | +const links = document.querySelectorAll(`ul.image-list a`); |
| 63 | + |
| 64 | +let svg_name_arr = []; |
| 65 | +let svg_url_obj = {}; |
| 66 | + |
| 67 | +for (let i = 0; i < links.length; i++) { |
| 68 | + if (links[i].getAttribute('class')) { |
| 69 | + let x = links[i].getAttribute('class'); |
| 70 | + let y = links[i].setAttribute('download', `${i}-${x}`.svg) |
| 71 | + svg_name_arr.push(x); |
| 72 | + let img = getComputedStyle(links[i], '::before').getPropertyValue('background-image'); |
| 73 | + let newImage = img.replace(/(url\(")|("\))/g,''); |
| 74 | + svg_url_obj[i] = newImage; |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +console.log(`svg_name_arr = \n`, svg_name_arr); |
| 79 | + |
| 80 | +console.log(`svg_url_obj = \n`, svg_url_obj); |
| 81 | + |
| 82 | +``` |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
0 commit comments