Example #1
0
 public function actionIndex()
 {
     $i = 1;
     for ($i = 1; $i < 2; $i++) {
         $simpleHTML = new SimpleHTMLDOM();
         $html = $simpleHTML->file_get_html("http://www.healthfamily.co/danh-sach-nha-thuoc-hieu-thuoc?p={$i}&r=100#.VavHvXj0HuU");
         foreach ($html->find('div.h125') as $element) {
             $name = $element->find('h3 a')->innertext;
             //  $address = $element->find('p.date-time', 0)->innertext;
             $pharmacy = new Pharmacy();
             $pharmacy->name = $name;
             $pharmacy->address = "";
             $pharmacy->save(FALSE);
         }
     }
     $this->render('index');
 }
 /**
  * 一次性导入优酷视频
  * Enter description here ...
  * @param unknown_type $courseId
  */
 public function actionYoukuPlayList($courseId = 0)
 {
     if (isset($_POST['url'])) {
         $url = $_POST['url'];
         //			$output = Yii::app()->curl->get($_POST['url']);
         //			$partern = "";
         Yii::import('ext.SimpleHTMLDOM.SimpleHTMLDOM');
         // Create DOM from URL or file
         $simpleHTML = new SimpleHTMLDOM();
         $html = $simpleHTML->file_get_html($url);
         $urlDict = array('playlist' => array('pattern' => "/\\/playlist_show\\/id_/i", 'selector' => '#list1_1 .items  li.v_title a'), 'episode' => array('pattern' => "/\\/show_page\\/id_/i", 'selector' => '#episode li.ititle_w a'));
         foreach ($urlDict as $key => $item) {
             if (preg_match($item['pattern'], $url)) {
                 $type = $key;
                 $selector = $item['selector'];
                 break;
             }
         }
         // Find all images
         foreach ($html->find($selector) as $elem) {
             $lesson = new Lesson();
             $lesson->courseId = $courseId;
             $lesson->title = $elem->getAttribute("title") ? $elem->getAttribute("title") : $elem->innertext;
             $pattern = "/id_(.*)\\/?\\.html/i";
             preg_match($pattern, $elem->href, $matches);
             if ($matches[1]) {
                 //		http://player.youku.com/player.php/sid/XNTk5MTQ3OTQ0/v.swf
                 $lesson->url = "http://player.youku.com/player.php/sid/{$matches['1']}/v.swf";
             } else {
                 continue;
             }
             $lesson->addTime = time();
             $lesson->save();
         }
         $this->redirect(array('lesson/editByCourse', 'courseId' => $courseId));
         Yii::app()->end();
     }
     $course = Course::model()->findByPk($courseId);
     $this->renderPartial("youkuPlayList", array('course' => $course), false, true);
 }