- function
insert($href='',$pattern='',$novel='',$author='')
- {
- $href =
"";
- $hrefb =
strrev($href);
- $hrefb =
strstr($hrefb,'/');
- $hrefb =
strrev($hrefb);
- $pattern =
'/\(.+?)\<\/a\>/i';
- $url =
curl_init($href);
- curl_setopt($url,CURLOPT_RETURNTRANSFER,true);
- try{
- $pdo = New
PDO('mysql:location=localhost;dbname=test','testuser','mytest');
- $pdo->query('set
names utf8');
- }catch( PDOException $e
){
- echo
$e->getMessage();
- }
- $string =
curl_exec($url);
- $string = iconv('gbk',
'utf-8', $string);
- preg_match_all( $pattern,
$string, $array );
- $stmt =
$pdo->prepare("insert into novel
(`novelName`,`author`,`chapterName`,`chapterinfo`,`chapterLink`)
values(?,?,?,?,?) ;");
- $j =
count($array[1]);
- echo '
';
- $novel =
'异界全职业大师';
- $author = '庄毕凡';
- for ($i = 0; $i < $j;
$i++) {
- $link =
$hrefb.$array[1][$i];
- $info =
$array[2][$i];
- $title =
$array[3][$i];
- $stmt->bindParam(1,
$novel) ;
- $stmt->bindParam(2,
$author);
- $stmt->bindParam(3,
$title);
- $stmt->bindParam(4,
$info);
- $stmt->bindParam(5,
$link);
- $rst =
$stmt->execute();
- $color = $rst ? 'green'
: 'red';
- echo
'
';
- echo '';
- echo $link;
- echo
'';
- echo
'
| ';
- echo '';
- echo $info;
- echo
'';
- echo
'
| ';
- echo '';
- echo $title;
- echo
'';
- echo
'
|
';
- if
(strstr($title,'大结局')!==false) {
- break;
- }
- }
- echo
'
';
- curl_close($url);
- }
- insert();
看到CURL采集就写了个采集某站的小说列表的函数,带插入数据库
应该还行,结合Linux再扩展一下就可以做个类似的booksky.org那样的站了
视频地址:
阅读(330) | 评论(0) | 转发(0) |