Да skyboy, да ты прав я реально вопросы плохо умею задавать, но к счастью всегда находились такие люди как ты и помагали!=)
Andres, поговорив со знакомым кодером я тоже пришел к такому решению, но спасибо=) Вроде все так просто удивляюсь почему сам не додумался... наверное моск автоматически отрубается ведь парсер написал осталась только эта фича чтобы ее на крон поставить и забыть. Ну и в конце хотелось бы критики и по больше, можете и с матом=) Буду рад любой критике вот это мой парсер
Код | set_time_limit(0); for($s = 2;$s <= 10; $s++){ $site[$s] = $s; $adres = file_get_contents('http://сайт_который_парсю.com/'.$site[$s]); preg_match_all('|<h3><a.* href=(.*)>(.*)</a></h3>|U', $adres, $mathesname); preg_match_all('/<p>(.*)<\/p>/',$adres,$mathesdesc); preg_match_all('/\/images\/icons\/([0-9]+)\/([0-9]+\.jpg)/',$adres,$mathesimg); preg_match_all('/price">(.*)<span class="cents">/',$adres,$mathesprise); preg_match_all('/cents">(.*)<\/span>/',$adres,$cent); preg_match_all('/<\/span><a.* href=(.*)>(.*)<\/a><\/div>/',$adres,$priselink); preg_match_all('/category">(.*)<\/div>/',$adres,$mathescat); $namearray = $mathesname[2]; $decsarray = $mathesdesc[1]; $id_cat = $mathesimg[1]; $id_icon = $mathesimg[2]; $prisearr = $mathesprise[1]; $prisecent = $cent[1]; $catarr = $mathescat[1]; $prlink = $priselink[1]; $date=date("Y-m-d h:i:s"); for($i=0,$ind=0;$i < count($namearray) && count($decsarray) && count($id_icon) && count($prisearr) && count($prisecent) && count($prlink) && count($catarr),$ind < 20;$i++,$ind++){ $val[$ind]=$ind; $fh = fopen($id_icon[$i], 'w'); $img = file_get_contents('http://сайт_который_парсю.com/images/icons/'.$id_cat[$i].'/'.$id_icon[$i]); $fw = fwrite($fh, $img); if ($prisearr[$i]){ $prisearr[$i].='.'; } mysql_query("INSERT INTO `wp_posts` (`post_date`,`post_author`,`post_title`,`post_content`,`post_parent`) VALUES ('".$date."',1,'".$namearray[$i]."','<img src=http://мой_сайт.ru/wp-content/uploads/2008/10/$id_icon[$i] hspace=10 align=left>$decsarray[$i] <strong> цена: $prisearr[$i] $prisecent[$i] <a href=$prlink[$i]>купить</a></strong>','".$val[$ind]."');"); //тут условия типа if (($catarr[$i])=='Photography'){ mysql_query("INSERT INTO `wp_term_relationships` (`object_id`,`term_taxonomy_id`) VALUES ('".mysql_insert_id()."',14);"); } // категорий куча и поэтому код не много обрезаю mysql_query("INSERT INTO `wp_term_relationships` (`object_id`,`term_taxonomy_id`) VALUES ('".mysql_insert_id()."',1);"); mysql_query("INSERT INTO `wp_posts` (`post_date`,`post_author`,`post_title`,`post_parent`,`post_type`,`guid`,`post_mime_type`,`post_status`) VALUES ('".$date."',1,'".$id_icon[$i]."','".$val[$ind]."','attachment','http://мой_сайт.ru/wp-content/uploads/2008/10/$id_icon[$i]','image/jpeg','inherit');"); fclose($fh); } }
|
|