diff --git a/application/third_party/tripadvisor_spider/controllers/index.php b/application/third_party/tripadvisor_spider/controllers/index.php index 988b8369..869015c9 100644 --- a/application/third_party/tripadvisor_spider/controllers/index.php +++ b/application/third_party/tripadvisor_spider/controllers/index.php @@ -268,30 +268,64 @@ class Index extends CI_Controller { } } - public function get_destination_reviews($destination = null,$pagenum = null){ + //获取目的地 + public function get_destination_reviews(){ set_time_limit(0); $ta_website = $this->config->item('tripadvisor_website'); + $destination = $this->input->get_post('destination'); + $pagenum = $this->input->get_post('pagenum'); + $product_links = $this->input->get_post('product_links'); - //根据传入的目的地简码获取TA的相应评论列表 - if(isset($ta_website[$destination])){ - $url = $ta_website[$destination]; + if($product_links != ''){ if($pagenum != ''){ - $url = str_replace('{PAGENUM}','-or'.$pagenum,$url); + $product_links = str_replace('{PAGENUM}','-or'.$pagenum,$product_links); }else{ - $url = str_replace('{PAGENUM}','',$url); + $product_links = str_replace('{PAGENUM}','',$product_links); } - //根据url获取页面内容 + $content = GET_HTTP($product_links); + + $html_object = str_get_html($content); + + $urlList = $html_object->find('._1T1U92WJ ._2cigFICy a'); + + $data = new stdClass(); + $data->urls = array(); + + foreach ($urlList as $key=>$url){ + $data->urls[$key] = 'https://www.tripadvisor.com'.$url->href; + } + + print_r(json_encode($data)); + }else{ + return ; + } + } + + //获取产品内评论URL + public function get_reviews_url(){ + set_time_limit(0); + $url = $this->input->get_post('url'); + + $url = 'https://www.tripadvisor.com/AttractionProductReview-g294212-d11463418-Mini_Group_2_Day_Beijing_Highlights_and_Great_Wall_Tour-Beijing.html'; + + if($url != ''){ $content = GET_HTTP($url); - //进行页面解析 + $html_object = str_get_html($content); - $return = new stdClass(); - $return->urls = array(); - //获取每个页面上的url - foreach ($html_object->find('.reviewSelector .quote a') as $reviews_url){ - array_push($return->urls,'https://www.tripadvisor.com'.$reviews_url->href); + + $urlList = $html_object->find('._1T1U92WJ ._2cigFICy a'); + + $data = new stdClass(); + $data->urls = array(); + + foreach ($urlList as $key=>$url){ + $data->urls[$key] = 'https://www.tripadvisor.com'.$url->href; } - print_r(json_encode($return)); + + print_r(json_encode($data)); + }else{ + return ; } } @@ -312,6 +346,7 @@ class Index extends CI_Controller { $html_num = $this->input->get_post('html_num'); $group_name = $this->input->get_post('group_name'); $guidename = $this->input->get_post('guidename'); + $product_code = $this->input->get_post('product_code'); //$url = 'https://www.tripadvisor.com/ShowUserReviews-g308272-d6222868-r599123490-Shanghai_Trippest_Mini_Group_Tours-Shanghai.html'; //$destination = 'tp_Beijing'; @@ -326,6 +361,7 @@ class Index extends CI_Controller { $detail_data->group_name = $group_name; $detail_data->links = $url; $detail_data->guidename = $guidename; + $detail_data->product_code = $product_code; //提取局部,不做整个页面的寻找元素,提升效率 $meta_inner = $html_object->find('.meta_inner'); @@ -413,4 +449,32 @@ class Index extends CI_Controller { print_r(json_encode($return_data)); } } + + public function get_production_code(){ + $destination = $this->input->get_post('destination'); + if($destination != ''){ + $productions_info = $this->Tripadvisor_Review_model->get_productions_info($destination); + print_r(json_encode($productions_info)); + } + } + + public function add_production(){ + $config_destination = $this->input->get_post('config_destination'); + $production_code = $this->input->get_post('production_code'); + $production_link = $this->input->get_post('production_link'); + + if($production_link != ''){ + //添加换页参数 + $arr = explode('-',$production_link); + $arr['2'] = $arr['2'].'{PAGENUM}'; + $production_link = implode('-',$arr); + + if($config_destination && $production_code && $production_link){ + $flag = $this->Tripadvisor_Review_model->add_config_production($config_destination,$production_code,$production_link); + exit('{"status":"200","reason":"添加成功"}'); + } + }else{ + exit('请输入参数'); + } + } } diff --git a/application/third_party/tripadvisor_spider/models/Tripadvisor_Review_model.php b/application/third_party/tripadvisor_spider/models/Tripadvisor_Review_model.php index ba12b652..8dca3e9f 100644 --- a/application/third_party/tripadvisor_spider/models/Tripadvisor_Review_model.php +++ b/application/third_party/tripadvisor_spider/models/Tripadvisor_Review_model.php @@ -182,12 +182,13 @@ class Tripadvisor_Review_model extends CI_Model { tr_gri_no, tr_links, tr_guidename, + tr_product_code, tr_datetime )values( - ?,?,?,?,?,?,?,?,?,?,?,?,?,GETDATE() + ?,?,?,?,?,?,?,?,?,?,?,?,?,?,GETDATE() ) "; - $query = $this->INFO->query($sql, array($detail_data->review_id,$detail_data->destination,$detail_data->review_id,$detail_data->title,$detail_data->content,$detail_data->review_name,$detail_data->user_loc,$detail_data->star_nums,$detail_data->rating_date,$detail_data->experience_date,json_encode($detail_data->pic),$detail_data->group_name,$detail_data->links,$detail_data->guidename)); + $query = $this->INFO->query($sql, array($detail_data->review_id,$detail_data->destination,$detail_data->review_id,$detail_data->title,$detail_data->content,$detail_data->review_name,$detail_data->user_loc,$detail_data->star_nums,$detail_data->rating_date,$detail_data->experience_date,json_encode($detail_data->pic),$detail_data->group_name,$detail_data->links,$detail_data->guidename,$detail_data->product_code)); //$result = $query->result(); } @@ -212,5 +213,17 @@ class Tripadvisor_Review_model extends CI_Model { $query = $this->INFO->query($sql,array($destination)); return $query->result(); } - + + public function add_config_production($config_destination,$production_code,$production_link){ + $sql = 'IF NOT EXISTS( + select trc_code from Ta_Reviews_Config where trc_code = ? + )insert into Ta_Reviews_Config (trc_destination,trc_code,trc_links) values (?,?,?)'; + $query = $this->INFO->query($sql,array($production_code,$config_destination,$production_code,$production_link)); + } + + public function get_productions_info($destination){ + $sql = 'select * from Ta_Reviews_Config where trc_destination = ?'; + $query = $this->INFO->query($sql,array($destination)); + return $query->result(); + } } diff --git a/application/third_party/tripadvisor_spider/views/third_party_input.php b/application/third_party/tripadvisor_spider/views/third_party_input.php index 0a67a39a..23daf969 100644 --- a/application/third_party/tripadvisor_spider/views/third_party_input.php +++ b/application/third_party/tripadvisor_spider/views/third_party_input.php @@ -19,6 +19,9 @@
5条评论链接获取成功,下面开始抓取具体评论!
'); + for(var x=0;xDate of experience: '+jsondata.list[y].tr_visited_date+'
Date of experience: '+jsondata.list[y].tr_visited_date+'
product code: '+jsondata.list[y].tr_product_code+'
total nums : '+jsondata.list.length+'
' $('#list_view_content').html(html); @@ -294,5 +392,36 @@ $(function(){ }); } }); + + //添加数据 + $('#addproduction').click(function (){ + var config_destination = $('#confg_destination').val(); + var production_code = $('input[name="production_code"]').val(); + var production_link = $('input[name="production_link"]').val(); + $(this).addClass('disabled'); + + if(config_destination && production_code && production_link){ + $.ajax({ + url : '/info.php/apps/tripadvisor_spider/index/add_production/', + data : { + config_destination : config_destination, + production_code : production_code, + production_link : production_link + }, + type:'POST', + success : function (json,status){ + var jsondata = $.parseJSON(json); + $('#confg_destination').val(''); + $('input[name="production_code"]').val(''); + $('input[name="production_link"]').val(''); + $('#addproduction').removeClass('disabled'); + alert(jsondata.reason); + } + }); + }else{ + alert('请输入完整参数'); + } + + }); }); \ No newline at end of file