<?php namespace Home\Controller; use Think\Controller; class CollectionController extends Controller { public function Collection(){ header("Content-Type: text/html;charset=utf-8"); // Initialize a cURL object $curl = curl_init(); // Set the URL you need to scrape curl_setopt($curl, CURLOPT_URL, 'http://fenxiang.banguanshui.com/'); // set header // curl_setopt($curl, CURLOPT_HEADER, 1); // Set cURL parameters, whether to save the result to a string or output to the screen. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // Run cURL, request the web page $data = curl_exec($curl); // close the URL request curl_close($curl); //$data is the value returned by curl_exec, that is, the collected target content preg_match_all('/<span class="username" (.*)>(.*)<\/span>/isU',$data, $asd, PREG_SET_ORDER); preg_match_all('/<h3><a href="(.*)" (.*)>(.*)<\/a>/',$data, $out, PREG_SET_ORDER); $row =array(); $i = 0; foreach($out as $key => $value){ //Here $value is an array, while recording the whole sentence with matching characters and the matching characters alone $row[1] = 'http://fenxiang.banguanshui.com/'.$value[1]; $row[2] = $value[3]; // foreach($asd as $key => $value){ // $row[3] = $value[2]; // } $row[3] = $asd[$i][2]; $i++; // dump($row);exit; $collection = M('collection'); $bata['url'] = $row[1]; $ seke = $ bata ['url']; // $ sdsa = $ bata ['title']; // print_r($seke);exit; // $blog1 = $collection->where(array('url' => $seke))->find(); $blog = $collection->where(array('url' =>$seke))->find(); // echo strlen($seke);exit; // print_r($blog1);exit; if($bata['url'] != $blog['url']){ $bata['title'] = $row[2]; $bata['author'] = $row[3]; $cent = $collection->add($bata); echo 'Added successfully'; dump($cent); } else{ echo 'Add failed'; } } } }
php collection website
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325394014&siteId=291194637
Ranking