当前位置: 首页>>代码示例>>PHP>>正文


PHP simple_html_dom::removeNode方法代码示例

本文整理汇总了PHP中simple_html_dom::removeNode方法的典型用法代码示例。如果您正苦于以下问题:PHP simple_html_dom::removeNode方法的具体用法?PHP simple_html_dom::removeNode怎么用?PHP simple_html_dom::removeNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在simple_html_dom的用法示例。


在下文中一共展示了simple_html_dom::removeNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ao3

function ao3($url)
{
    $time_start = microtime(true);
    //////// TESTING PURPOSES
    $chapters = array();
    $moreChapters = true;
    $story = new Story();
    //        echo "<p>old url = " . $url . "</p>"; //////// TESTING PURPOSES
    if (!strpos($url, "view_full_work=true")) {
        if (strpos($url, "view_adult=true")) {
            $url = $url . "&view_full_work=true";
        } else {
            $url = $url . "?view_full_work=true";
        }
    }
    if (!strpos($url, "view_adult=true")) {
        $url = $url . "&view_adult=true";
    }
    $redirect = true;
    $ch = curl_init();
    $page = new simple_html_dom();
    while ($redirect) {
        //            echo "<p>new url = $url</p>"; //////// TESTING PURPOSES
        curl_setopt($ch, CURLOPT_COOKIE, "birthtime=28801; path=/; domain=archiveofourown.org");
        curl_setopt($ch, CURLOPT_TIMEOUT, 50);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $result = curl_exec($ch);
        $page->load($result);
        $firsthref = $page->find('a', 0);
        if (strpos($firsthref->plaintext, "edirected")) {
            $url = $firsthref->getAttribute('href') . "?view_adult=true&view_full_work=true";
        } else {
            // --------- REMOVE THIS IF STATEMENT --------- \\
            // it's just for testing purposes, has no place in the final app.
            if ($page->find('#chapters')) {
                echo "<h1 style='color: red'>view_full_work mode worked!</h1>";
            }
            // -------------------------------------------- \\
            curl_close($ch);
            $redirect = false;
        }
    }
    /////////////////////////////////////////////////////////////////////////////////////////
    $story->title = trim($page->find('h2.title', 0)->plaintext);
    $story->author = $page->find('h3.byline a', 0)->plaintext;
    if ($page->find('#chapters .chapter')) {
        $story->totalChapters = count($page->find('#chapters .chapter div.userstuff'));
    } else {
        $story->totalChapters = 1;
    }
    echo "<p><span class='bold'>Execution time before for loop:</span> " . (microtime(true) - $time_start) . " seconds</p>";
    //////// TESTING PURPOSES
    for ($i = 0; $i < $story->totalChapters; $i++) {
        //            echo "loop $i<br>"; //////// TESTING PURPOSES
        $page->removeNode('div.chapter div.userstuff h3.landmark', 0);
        $chapter = new StoryChapter();
        $chapter->chapterID = $i;
        // if there is a chapter title, add it, else create a title
        $cID = "#chapter-" . ($i + 1);
        $chapterTitle = $page->find($cID . ' h3.title a', 0)->plaintext;
        if ($chapterTitle == null) {
            $chapter->chapterTitle = "Chapter " . ($i + 1);
        } else {
            $chapter->chapterTitle = $chapterTitle;
        }
        // if there are chapter notes, add them to chapter text
        $notes = "";
        if ($i == 0) {
            if ($page->find('div.preface div.summary')) {
                $story->summary = $page->find('div.preface div.summary blockquote', 0)->outertext;
            }
            if ($page->find('div.preface div.notes')) {
                $notes = "<div class='chapter-notes'><h4>Notes:</h4>" . $page->find('div.preface div.notes blockquote', 0)->outertext . "</div><hr>";
            }
        } else {
            if ($page->find($cID . ' div.notes')) {
                $notes = "<div class='chapter-notes'><h4>Notes:</h4>" . $page->find($cID . ' div.notes blockquote', 0)->outertext . "</div><hr>";
            }
        }
        if ($story->totalChapters == 1) {
            $chapter->chapterText = $notes . "<div class='chapter-text'>" . $page->find('#chapters div.userstuff', 0)->innertext . "</div>";
        } else {
            $chapter->chapterText = $notes . "<div class='chapter-text'>" . $page->find($cID . ' div.userstuff', 0)->innertext . "</div>";
        }
        $chapters[] = $chapter;
        // add Chapter object to chapters array
        echo "&nbsp;<span class='bold'>Loop {$i} execution time:</span> " . (microtime(true) - $time_start) . " seconds<br>";
        //////// TESTING PURPOSES
    }
    $story->chapters = $chapters;
    echo "<p><span class='bold'>Execution time after for loop:</span> " . (microtime(true) - $time_start) . " seconds</p>";
    //////// TESTING PURPOSES
    echo "<h1 id='top'>" . $story->title . "</h1>";
    echo "<h2>by " . $story->author . "</h2>";
    echo "<p><span class='bold'>Total number of chapters:</span> " . $story->totalChapters . ".</p>";
    if ($story->summary != null) {
        echo "<div id='story-summary'><span class='bold'>Summary:</span><br>" . $story->summary . "</div>";
    }
    $toc = "<p><span class='bold'>Table of Contents:</span></p><ol id='table-of-contents'>";
//.........这里部分代码省略.........
开发者ID:Angush,项目名称:spacebattles-fic-scraper,代码行数:101,代码来源:scraper.php


注:本文中的simple_html_dom::removeNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。