输出被多次提交

Pla*_*der 7 php

目前我正在使用simple_html_dom来搜索网站视图,以查看我正在抓取的网站,一切都回来了,除了它继续为每一个帖子添加相同的内容它查看 .. 查看此处查看演示

$page = (isset($_GET['p'])&&$_GET['p']!=0) ? (int) $_GET['p'] : '';  
$html = file_get_html('http://screenrant.com/movie-news/'.$page);

foreach($html->find('#site-top > div.site-wrapper > div.top-content > article > section > ul > li > div.info > h2 > a') as $element)
{
    print '<br><br>';
    echo $url = ''.$element->href;
    $html2 = file_get_html($url);

    $image = $html2->find('meta[property=og:image]',0);
    $news['image'] = $image->content;
    #print '<br><br>';

    // Ending The Featured Image

    #site-top > div.site-wrapper > div.top-content > article > section > ul > li:nth-child(2)

    $title = $html2->find('#site-top > div.site-wrapper > div.top-content > article > header.single-header > h1',0);
    $news['title'] = $title->plaintext;

    // Ending the titles
    print '<br>';
    #site-top > div.site-wrapper > div.top-content > article > div
    $articles = $html2->find('#site-top > div.site-wrapper > div.top-content > article > div > p');
    foreach ($articles as $article) {
    #echo "$article->plaintext<p>"; 
    $news['content'] = $news['content'] . $article->plaintext . "<p>";
    }

    print '<pre>';print_r($news);print '</pre>';

    print '<br><br>';

        // mysqli_query($DB,"INSERT INTO `wp_scraped_news` SET
             //                   `hash` = '".$news['title']."',
               //                 `title` = '".$news['title']."',
                 //               `image` = '".$news['image']."',
                   //             `content` = '".$news['content']."'");
         // print '<pre>';print_r($news);print '</pre>';
}
Run Code Online (Sandbox Code Playgroud)

我不知道我在哪里错了,但我认为这是两件事之一,我已经搞砸了这两件事,没有运气.

我对自己foreach的布局做错了.

该网站正在改变每篇新文章的选择者.

在这两种情况下,我可能都错了..但是我现在已经和他们一起修整了大约2个小时并放弃了...任何帮助都非常感激.

Bar*_*mar 4

问题是您没有清除 中的旧内容$news['content']。因此,当您处理第二页时,您会将其内容附加到第一页的内容中。第三页再次附加到此,依此类推。

$news['content'] = '';
Run Code Online (Sandbox Code Playgroud)

foreach ($articles as $article) {
Run Code Online (Sandbox Code Playgroud)