79731653

Date: 2025-08-11 04:22:22
Score: 1
Natty:
Report link

@Mnyikka's answer didn't work for me, but inspired me to write this:

    function ExtractFromDiv(html, id) {
        do {
            let i = html.indexOf("<div");
            if (i < 0) { return '' };
            html = html.substring(i);
            i = html.indexOf(">");
            let tag = html.substring(0, i + 1);
            html = html.substring(i + 1);
            i = tag.indexOf('id="');
            if (i < 0) {
                i = tag.indexOf("id='");
                if (i < 0) { continue };
                tag = tag.substring(i + 4);
                i = tag.indexOf("'");
                if (i < 0) { continue };
                tag = tag.substring(0, i);
                if (tag !== id) { continue };
                break;
            } else {
                tag = tag.substring(i + 4);
                i = tag.indexOf('"');
                if (i < 0) { continue };
                tag = tag.substring(0, i);
                if (tag !== id) { continue };
                break;
            }
        } while (html.length > 0);
        if (html.length === 0) { return '' };
        let content = html;
        let n = 0;
        do {
            let x = content.indexOf('<div');
            let y = content.indexOf('</div');
            if (x < 0 || x > y) {
                content = content.substring(y);
                y = content.indexOf(">");
                content = content.substring(y + 1);
                if (n === 0) {
                    break;
                } else {
                    n--;
                }
            } else {
                content = content.substring(x);
                x = content.indexOf(">");
                content = content.substring(x + 1);
                n++;
            }
        } while ( content.length > 0 );
        html = html.substring(0, html.length - content.length);
        n = html.lastIndexOf("</div");
        if (n !== -1 ) {
            html = html.substring(0, n);
        }
        return html;
    }
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Mnyikka's
  • Looks like a comment (1):
  • Low reputation (0.5):
Posted by: Steve Mol