protected function prepDocument()
    {
        /*
         * In some cases a body element can't be found (if the HTML is totally hosed for example)
         * so we create a new body node and append it to the document.
         */
        if (null === $this->body) {
            $this->body = $this->dom->createElement('body');
            $this->dom->documentElement->appendChild($this->body);
        }

        $this->body->setAttribute('class', 'readabilityBody');

        // Remove all style tags in head.
        $styleTags = $this->dom->getElementsByTagName('style');
        for ($i = $styleTags->length - 1; $i >= 0; --$i) {
            $styleTags->item($i)->parentNode->removeChild($styleTags->item($i));
        }

        $linkTags = $this->dom->getElementsByTagName('link');
        for ($i = $linkTags->length - 1; $i >= 0; --$i) {
            $linkTags->item($i)->parentNode->removeChild($linkTags->item($i));
        }
    }
protected function prepDocument()
    {
        /*
         * In some cases a body element can't be found (if the HTML is totally hosed for example)
         * so we create a new body node and append it to the document.
         */
        if (null === $this->body) {
            $this->body = $this->dom->createElement('body');
            $this->dom->documentElement->appendChild($this->body);
        }

        $this->body->setAttribute('class', 'readabilityBody');

        // Remove all style tags in head.
        $styleTags = $this->dom->getElementsByTagName('style');
        for ($i = $styleTags->length - 1; $i >= 0; --$i) {
            $styleTags->item($i)->parentNode->removeChild($styleTags->item($i));
        }

        $linkTags = $this->dom->getElementsByTagName('link');
        for ($i = $linkTags->length - 1; $i >= 0; --$i) {
            $linkTags->item($i)->parentNode->removeChild($linkTags->item($i));
        }
    }
protected function prepDocument ( ) { /*
         * In some cases a body element can't be found (if the HTML is totally hosed for example)
         * so we create a new body node and append it to the document.
         */ if ( null === $ this -> body ) { $ this -> body = $ this -> dom -> createElement ( 'body' ) ; $ this -> dom -> documentElement -> appendChild ( $ this -> body ) ; } $ this -> body -> setAttribute ( 'class' , 'readabilityBody' ) ; // Remove all style tags in head. $ styleTags = $ this -> dom -> getElementsByTagName ( 'style' ) ; for ( $ i = $ styleTags -> length - 1 ; $ i >= 0 ; -- $ i ) { $ styleTags -> item ( $ i ) -> parentNode -> removeChild ( $ styleTags -> item ( $ i ) ) ; } $ linkTags = $ this -> dom -> getElementsByTagName ( 'link' ) ; for ( $ i = $ linkTags -> length - 1 ; $ i >= 0 ; -- $ i ) { $ linkTags -> item ( $ i ) -> parentNode -> removeChild ( $ linkTags -> item ( $ i ) ) ; } }
Prepare the HTML document for readability to scrape it.
This includes things like stripping javascript, CSS, and handling terrible markup.
Prepare the HTML document for readability to scrape it . This includes things like stripping javascript CSS and handling terrible markup .