标签:tps htm find title char ror color mes this
本文介绍如何抓取滴滴打车优惠券
券妈妈。
使用simple_html_dom的方式先抓取整个页面,再进行元素分析。
实现代码如下
<?php header("Content-type: text/html; charset=utf-8"); require_once(‘simple_html_dom.php‘); $index = 0; $total = 0; $html = file_get_html(‘http://www.quanmama.com/quan/1718911.html‘); $html_bj_content = $html->find(‘table tbody‘, 0); echo $html_bj_content; foreach($html_bj_content->find(‘tr‘) as $item) { $title = $item->find(‘td‘, 0)->plaintext; $source = $item->find(‘td a‘, 0)->href; // echo $source; $total ++; if (false == stristr($source, "gsactivity.diditaxi.com.cn/gulfstream/activity/v2/giftpackage")){ continue; }else{ try { $channels = explode(‘g_channel=‘,$source); $data = array(‘title‘ => $title, ‘source‘ => "https://gsactivity.diditaxi.com.cn/gulfstream/activity/v2/giftpackage/index?g_channel=".$channels[1], ‘channel‘ => $channels[1] ); // var_dump($data); $diditrip = M(‘diditrip‘,‘tp_‘); $isadd = $diditrip ->add($data); if ($isadd){ $index ++; } } catch (\Exception $e) { // $res = array("code" => "error", "message" => "数据库错误"); } } } // $this->success(‘同步‘.$total.‘条,成功‘.$index."条",‘index‘); ?>
标签:tps htm find title char ror color mes this
原文地址:https://www.cnblogs.com/txw1958/p/crawler-didi.html