[Node.js] Scraping all Responsive CSS Templates from https://www.free-css.com/template-categories/responsive by cryptosharon

View this thread on steempeak.com
· @cryptosharon · (edited)
$13.70
[Node.js] Scraping all Responsive CSS Templates from https://www.free-css.com/template-categories/responsive
![image.png](https://ipfs.busy.org/ipfs/QmWZEyU85cKJKegJshCGqLdVrArpWBgtXwPmXoyyuxGnzr)


![image.png](https://ipfs.busy.org/ipfs/QmSYwbLBSwpbfVAj4BFg3ykUDmXg2nUko8HwhbRLdjYg3S)

I spent a couple hours developing a bit of code because I wanted to download all of the responsive CSS templates on free-css.com. It was a very pleasant experience. Coding, scraping, so much love. ♥♥

I saved my code in a Gist in case you want to  see it (or use it, or modify it):

https://gist.github.com/CryptoSharon/f0face4028b6e3cd1a32e519a0ea68ac

Nananananana, still scraping.

![image.png](https://ipfs.busy.org/ipfs/QmQcMn47hocgeS4V4vRD7Btpjx9enDYvVU6YFJELotMB3S)

I would have run it on my server to share the big file on here, but I wasn't thinking ahead or planning to share it. Hmmm. I guess if you want it, you'll have to scrape it too? That would be mean to free-css, so much good work and we're spamming their website with scrapers.

<h2>About the code</h2>

I'm using a few cool libraries that I love, i.e.: cheerio, request-promise, bluebird and fs-extra. The traditional way would have been using just cheerio, request and fs, but I love promisifying everything. I also like the extra functionalities that fs.extra provides! The `fs.pathExists(path)` is wonderful. The traditional `fs` library wanted me to do some weird `fs.access(path)` thingy and then use a property of one of the various results given? Ugly solution.

I also learned that Cheerio apparently doesn't have the same `.attr('href')` as jQuery. Instead, I had to run `$('a').attribs.href`. After about half an hour of trying out things in jQuery, then trying them out on Cheerio and comparing the errors and logging the results, I managed to properly grab each URL link (12 per page) to add it to the array that would be downloaded in the end.

I also discovered that I can make a delayed loop with this wonderful, wonderful function!

```js
const awaitForEach = async (fn, arr) => {
	for (const el of arr) {
		await fn(el)
	}
}
```

Props to [this blogger](https://blog.lavrton.com/javascript-loops-how-to-handle-async-await-6252dd3c795) for showing me how to do that.

I was doing everything functionally, but I got very sleepy, bored and tired when I got to some unexpected errors and the `getZip()` function ended up imperative. Sad ¯\\\_(ツ)_/¯, but I was getting impatient after 2 hours of coding pretty things.

Another thing to note is that not all of the files are straightforwardly downloaded. Some files, when you request them, tell you that they're not available, but that there are similar files that are available. It gives you options. I had to create this tiny piece of code to handle this Error Status 300, download files and continue with the rest of the stack.

```js
.catch(e => {
	if (e.statusCode === 300) {
		const $ = cheerio.load(e.error)
		const links = $('li a').map((i, el) =>
			({ zip_link: baseUrl + el.attribs.href }))
		downloadAllLinks(Array.from(links))
	} else {
		console.error(e)
	}
})
```

I also discovered that `$().map` doesn't return an iterable array! It's like `{0: value1, 1: value2, ...randomObject}`. It has 0, 1, 2, etc., so I could basically do `Array.from(cheerioMappedArray)` and get a valid array without object thingies so that it could be iterated by my `awaitForEach()`. I explored a few other options but the normal `.map` and ramda's `map` also attach the strange object to the array. Only `Array.from` could create a shallow clone taking only the iterable properties.

<h2>File size average</h2>

Okay! The files are done downloading. 658 files, 1.72 GB.
1.72*1024 = 1761.28
1761.28/658 = 2.676

The average size of the zipped templates is 2.6 megabytes. Not big, not small. I hope to find a use for all of this. I would be a good [DataHoarder](https://www.reddit.com/r/DataHoarder/) if I had any money to buy HDD's and SSD's. Instead, I'll probably have to delete it in a few months to get space for other scrapes and downloads.

Alrighty then, this was fun.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 126 others
properties (23)
post_id66,504,561
authorcryptosharon
permlinknode-js-scraping-all-responsive-css-templates-from-https-www-free-css-com-free-css-templates
categoryprogramming
json_metadata{"format":"markdown","tags":["programming","nodejs","javascript","busy","ulog"],"links":["https:\/\/gist.github.com\/CryptoSharon\/f0face4028b6e3cd1a32e519a0ea68ac","https:\/\/blog.lavrton.com\/javascript-loops-how-to-handle-async-await-6252dd3c795","https:\/\/www.reddit.com\/r\/DataHoarder\/"],"app":"steemit\/0.1","community":"busy","image":["https:\/\/ipfs.busy.org\/ipfs\/QmWZEyU85cKJKegJshCGqLdVrArpWBgtXwPmXoyyuxGnzr"]}
created2018-11-24 05:00:30
last_update2018-11-24 05:11:57
depth0
children4
net_rshares22,369,855,675,379
last_payout2018-12-01 05:00:30
cashout_time1969-12-31 23:59:59
total_payout_value10.475 SBD
curator_payout_value3.220 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length3,981
author_reputation80,455,466,172,351
root_title"[Node.js] Scraping all Responsive CSS Templates from https://www.free-css.com/template-categories/responsive"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (190)
@gatillo ·
re-cryptosharon-node-js-scraping-all-responsive-css-templates-from-https-www-free-css-com-free-css-templates-20181124t051500087z
## <center> Este Post ha sido votado por @gatillo y curado por @bebeth para @steempress-io</center>
---
<div class="pull-right">

![https://discord.gg/AgtNh53](https://steemitimages.com/160x160/https://cdn.steemitimages.com/DQmbj4qsgp3RPznnnLEDmA3oqk5b6AekNMDxHvaGT2JkriF/SELLO%20BEBECTH%20OSCURO.png)
 </div>
<br/>
Ya que utiliza el servicio de hospedaje de WordPress de @reveur y el plugin de @steempress-io para publicar contenido en nuestro idioma, el #castellano, si deseas saber mas o formar parte, haz click en la imagen para entrar a nuestro discord.
<br/>

---
<center> Un proyecto del **Witness: @castellano** y **@nnnarvaez** </center>
properties (22)
post_id66,504,936
authorgatillo
permlinkre-cryptosharon-node-js-scraping-all-responsive-css-templates-from-https-www-free-css-com-free-css-templates-20181124t051500087z
categoryprogramming
json_metadata{"app":"communitybot\/1.1.0"}
created2018-11-24 05:15:00
last_update2018-11-24 05:15:00
depth1
children0
net_rshares0
last_payout2018-12-01 05:15:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length646
author_reputation111,629,191,115
root_title"[Node.js] Scraping all Responsive CSS Templates from https://www.free-css.com/template-categories/responsive"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@cryptotrader84 ·
$0.07
Nice stuff i think i can use it for some of my projects
👍  , ,
properties (23)
post_id66,506,082
authorcryptotrader84
permlinkre-cryptosharon-node-js-scraping-all-responsive-css-templates-from-https-www-free-css-com-free-css-templates-20181124t055940844z
categoryprogramming
json_metadata{"app":"steemit\/0.1","tags":["programming"]}
created2018-11-24 05:59:42
last_update2018-11-24 05:59:42
depth1
children0
net_rshares115,994,487,928
last_payout2018-12-01 05:59:42
cashout_time1969-12-31 23:59:59
total_payout_value0.054 SBD
curator_payout_value0.017 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length55
author_reputation10,660,504,989,847
root_title"[Node.js] Scraping all Responsive CSS Templates from https://www.free-css.com/template-categories/responsive"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (3)
@ocdb ·
re-cryptosharon-node-js-scraping-all-responsive-css-templates-from-https-www-free-css-com-free-css-templates-20181124t073733763z
You got a 36.57% upvote from @ocdb courtesy of @cryptosharon!

@ocdb is a non-profit bidbot for whitelisted Steemians, current max bid is 20 SBD and the respective amount in Steem.
Check our website https://thegoodwhales.io/ for the whitelist, queue and delegation info. Join our [Discord channel for more information.](https://discord.gg/k2Hu77b)

If you like what @ocd does, consider voting for [ocd-witness through SteemConnect](steemconnect.com/sign/account-witness-vote?witness=ocd-witness&approve=1) or on the Steemit Witnesses page. :)
properties (22)
post_id66,508,518
authorocdb
permlinkre-cryptosharon-node-js-scraping-all-responsive-css-templates-from-https-www-free-css-com-free-css-templates-20181124t073733763z
categoryprogramming
json_metadata{"app":"postpromoter\/1.9.3"}
created2018-11-24 07:37:33
last_update2018-11-24 07:37:33
depth1
children0
net_rshares0
last_payout2018-12-01 07:37:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length542
author_reputation3,405,824,162,324
root_title"[Node.js] Scraping all Responsive CSS Templates from https://www.free-css.com/template-categories/responsive"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@steem-ua ·
#### Hi @cryptosharon!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your **UA** account score is currently 4.437 which ranks you at **#2104** across all Steem accounts.
Your rank has dropped 19 places in the last three days (old rank 2085).

In our last Algorithmic Curation Round, consisting of 212 contributions, your post is ranked at **#172**.
##### Evaluation of your UA score:

* Some people are already following you, keep going!
* The readers appreciate your great work!
* Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!


**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
post_id66,520,097
authorsteem-ua
permlinkre-node-js-scraping-all-responsive-css-templates-from-https-www-free-css-com-free-css-templates-20181124t140930z
categoryprogramming
json_metadata{"app":"beem\/0.20.9"}
created2018-11-24 14:09:33
last_update2018-11-24 14:09:33
depth1
children0
net_rshares0
last_payout2018-12-01 14:09:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length737
author_reputation23,203,609,903,979
root_title"[Node.js] Scraping all Responsive CSS Templates from https://www.free-css.com/template-categories/responsive"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000