Пример #1
0
 public function processArticle()
 {
     $article = \MkmScraper\Article::create(array("popularity" => \Input::get("popularity"), "publisher" => \Input::get("publisher"), "link" => \Input::get("url")));
     $client = new \Goutte\Client();
     $crawler = $client->request('GET', \Input::get("url"));
     if (\Input::get("publisher") == "1") {
         $text = $crawler->filter("#article_content")->text();
         $title = $crawler->filter("#article_title h2")->text();
         $date = $crawler->filter("#article_date")->text();
     }
     if (\Input::get("publisher") == "2") {
         $text = $crawler->filter(".postContent")->text();
         $title = $crawler->filter(".postTitle")->text();
         $auth = $crawler->filter(".byAuthor")->text();
         $au = explode("//", $auth);
         $date = trim(preg_replace('#[^A-Za-z0-9-, /]#', '', $au[1]));
     }
     if (\Input::get("publisher") == "3") {
         $text = $crawler->filter("#blackborder_main_wrapper .content .field-name-body")->text();
         echo $text;
     }
     if (\Input::get("publisher") == "4") {
         $text = $crawler->filter(".articleBody")->text();
         echo $text;
     }
     $article->text = $text;
     $article->title = $title;
     $article->date = date("Y-m-d", strtotime($date));
     $article->save();
     return redirect("articles")->with(array("message" => "Article <b>" . $article->title . "</b> was successfully entered."));
 }