お世話になります
cakePHP Ver2.7を勉強中でスクレイピングの勉強をしています。
スクレイピングまでは出来るようになったのですがそれをDBに保存する方法でつまずいています。
DBにはtaskと言うテーブルを作成して
id
title
url
category
price
を作成しています。
TestController.phpに下記の内容で記述しています。
php
1<?php 2App::import('Vendor', 'simple_html_dom'); 3App::import('Vendor', 'pathreplace_class'); 4class ShdController extends AppController { 5 public $helpers = array('Html', 'Form'); 6 public function index() { 7 $site_url='http://www.lancers.jp'; 8 $html = file_get_html( 'http://www.lancers.jp/work/search/all?new=1&completed=0&sort=Work.started&direction=desc#' ); 9 10 foreach($html->find('table.prof') as $entry){ 11 $title = $entry->find('p.work_title a',0); 12 $user_url = $entry->find('p.work_title a',0)->href; 13 $price = $entry->find('p.red',0); 14 $category=$entry->find('p.category a',0); 15 $this->Post->id = false; 16 $this->Post->save($title); 17 //$html = "<p>" . $title->innertext. "</p>" ; 18 //echo $site_url.$user_url. "<br>"; 19 //echo $price ->innertext."<br>"; 20 //echo $category->innertext."<br>"; 21 //echo $user_url."<br>"; 22 //echo $id=str_replace("/work/detail/","",$user_url)."<br>"; 23 24 } 25 26 } 27}
現状はエラーが出るところで悩み中です。
Viewはindex.ctpを空ファイルで作成しています。
Modelは作成していません。
可能であれば重複チェック機能も入れたいのですが
参考サイトかアドバイスを頂ければ幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/25 02:29