Build a Stack Exchange Scraper

  • + 0 comments

    Javascript: //(.?) --> It will stop until the and characters else . will become greedy and match all the content without stopping.

    // /gs --> The dotAll flag(s) changes the behavior of the. (dot) metacharacter in the regular expression. by default . matches any charactes in the regex except newLine characters \n by adding /s dotAll flag . will consider the newline \n characters as well/gs.

    const splitInput = input.split('class="question-summary"'); 
    if (splitInput && splitInput.length) {
         splitInput.forEach(question => {
            const regexContent = /.*question-summary-([0-9]+).*?class="question-hyperlink">(.*?)<\/a\>.*class="relativetime">(.*?)<\/span>.*/gs;
            const replaceContentexec = regexContent.exec(question);
            if (replaceContentexec) {
                replaceContentexec.shift();
                console.log(replaceContentexec.join(';'));   
            }
         })   
    }