Search code examples
javascriptweb-scrapingdataminer

Scraping - Clean up scrape with non constant data


I'm doing some web scraping.

My output data is in Column 1:

Submission date: YYYY-MM-DD HH:MM

i only need YYYY-MM-DD

i've added this script to remove "Submission date: "

var cleanup = function(results) {

  $.each(results, function(){                

   this.values[0] = this.values[0].replace("Submission date: ", "");
        this.values[1] = this.values[1].replace("Case number: ", "");

  });

  return results;                           
};

How do i remove HH:MM? keep in mind the data gonna change everytime


Solution

  • An easy way might be to split the string on its delimiter. Given a string like "2019-1-20 12:30", split at the delimiter, in this case the space:

    var value = "2019-1-20 12:30";
    var parts = value.split(" "); // ["2019-1-20", "12:30"]
    var dateOnly = parts[0];