title: How to export data from website to csv file using Javascript?
body: <p>I saw this code from a website and apparently it works on other people even for my friend but not for me. I am using Nodejs and express. Am i doing it wrongly or did i miss out any important parts? After the button was clicked, that was no pop out of the file directory or anything and there is no error to be seen as well. </p>
  
  <p>This are the codes from the script.</p>
  
  <pre><code>&lt;script&gt;
          function downloadCSV(csv, filename) {
              var csvFile;
              var downloadLink;
              //var charset = "UTF-8";
  
              // CSV File
              csvFile = new Blob([csv], {type: "text/csv"});
  
              // download link
              downloadLink = document.createElement("a");
  
              // file name
              downloadLink.download = filename;
  
              // create link to file
              downloadLink.href = window.URL.createObjectURL(csvFile);
  
              // hide download link
              downloadLink.style.display = "";
  
              // add link to DOM
              document.body.appendChild(downloadLink);
  
              // click download link
              downloadLink.click();
          }
  
          function exportData(html,filename) {
              var csv = [];
              var rows = document.querySelectorAll("table tr");
  
              for (var i=0; i&lt;rows.length; i++) {
                  var rows = [], cols = rows[i].querySelectorAll("td, th");
  
                  for (var j=0; j&lt;cols.length; j++) {
                      if (j == 7) {
                          row.push("'" + cols[j].innerText + "'");
                      } 
                      else if (j == 2){
                          row.push("'" + cols[j].innerText + "'");
                      } 
                      else {
                          row.push(cols[j].innerText);
                      }
                  }
  
                  csv.push(row.join(","));
              }
  
              // download csv file
              downloadCSV(csv.join("\n"), filename);
  
          }
      &lt;/script&gt;
  </code></pre>
  
  <p>This are the codes from the design part. </p>
  
  <pre><code>  &lt;button type="button" class="btn btn-primary" id="exportBtn" onclick="exportData(null,'scrapedData.csv')"&gt;导出&lt;/button&gt;
  </code></pre>