DEV Community

Discussion on: Get paid to write technical articles

Collapse
 
medosa profile image
Mark Edosa • Edited

DOWNLOAD this cool content as a CSV File. The file includes the company name, link, pricing, and areas of interest.

I like how you wrote this article in a consistent manner. It made it easy to extract the content.

Here's the CSV file. You can add other fields in case you want to keep track of your application(s) to any of the platforms.

Here's the code just for fun :)

// taken from https://stackoverflow.com/questions/21012580/is-it-possible-to-write-data-to-file-using-only-javascript
var textFile = null,
  makeTextFile = function (text) {
    var data = new Blob([text], {type: 'text/plain'});

    // If we are replacing a previously generated file we need to
    // manually revoke the object URL to avoid memory leaks.
    if (textFile !== null) {
      window.URL.revokeObjectURL(textFile);
    }

    textFile = window.URL.createObjectURL(data);

    // returns a URL you can use as a href
    return textFile;
  };


function download(content) {
    const link = document.createElement('a');
    link.setAttribute('download', 'get-paid-to-write-technical-articles.csv');
    link.href = makeTextFile(content);
    link.click();
}

let csv = 'Company,Link,Price,Area\n';
let headings = document.querySelectorAll('h2');

// deviated from the pattern.
const excepts = ['codingsight', 'cohesive'];

function extractDetails(heading) {
   // Each heading has two <a> children
    let aTags = heading.querySelectorAll('a')
    if (aTags?.length === 2) {
        // The second <a> tag contains the company name and link
        let h = aTags[1];
        let company = h.textContent.trim();
        let link = h.href;

        // Extract content
        let content = heading.nextElementSibling;
        let els = content.querySelectorAll('li');

        let price, area; 
        if (excepts.includes(company.toLowerCase())) {
            price = els[1]?.textContent.trim();
            area = els[2]?.textContent.trim() + ' ' + els[0].textContent.trim();
        } else {
            price = els[0]?.textContent.trim();
            area = els[1]?.textContent.trim();
        }

        return (price && area) ? `${company},${link},${price},\"${area}\"\n` : '';
    }
    return ''; 
}

// build csv
headings.forEach(h => {
    const details = extractDetails(h);
    csv += details;
})

// console.log(csv);

download(csv);
Enter fullscreen mode Exit fullscreen mode

To run the code yourself, do the following on this page:

  • open your browser dev tools
  • go to the sources tab or anywhere you can paste and run the code well, run it :)

Open the downloaded CSV file in a spreadsheet and add other columns to keep track of your applications.