Home > php教程 > php手册 > Curl write request to steal Jinshi.com homepage data, with thinkphp source code package attached

Curl write request to steal Jinshi.com homepage data, with thinkphp source code package attached

WBOY
Release: 2016-09-15 11:14:46
Original
1116 people have browsed it

After playing with curl, I found that php regularization is really important, but unfortunately I am very bad at it. I took three fields on the web page and wrote a demo. Copy the code posted below and run it directly. In fact, it is an idea of ​​​​using other people's data to make your own API.
<?php <br /> function getwebcontent($url){ <br> $ch = curl_init(); <br> curl_setopt($ch, CURLOPT_URL, $url); <br> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); <br> curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); <br> $contents = trim(curl_exec($ch)); <br> curl_close($ch); <br> Return $contents; <br> } <br> function DeleteHtml($str) { <br>       $str = trim($str); <br> $str = str_replace("t","",$str); <br> $str = str_replace("rn","",$str); <br> $str = str_replace("r","",$str); <br> $str = str_replace("n","",$str); <br> Return trim($str); <br> }<br> ​​​set_time_limit(0);<br> $datas =DeleteHtml(getwebcontent('http://www.jin10.com')); <br> Preg_match_all('/(d{2}:d{2})/',$datas,$time); /*All corresponding times*/<br> preg_match_all('/<td>]+?ids*?=s*?"content_d+?">(.+?)</td>/',$datas,$content); /*Corresponding All content*/<br> Preg_match_all('/"General news"|"Important news"|"General data"|"Important data"/',$datas,$importance); /*The importance of all corresponding news*/<br> $contents=$content[1]; /*All corresponding contents*/<br> $times=$time[1]; /*All corresponding times*/<br> $importances=$importance[0];<br> <br> $news=[];<br> foreach ($contents as $key => $value) {<br>          $t=[<br> "content"=>$value,<br> "time"=>$times[$key],<br> “Importance”=>str_replace('"','',$importances[$key]),<br> ];<br>           array_push($news,$t);<br> }<br> var_dump($news);<br> <br> ?>

Curl write request to steal Jinshi.com homepage data, with thinkphp source code package attached 109news.rar ( 1.12 MB Download: 7 times )

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template