php качаем новости автомира url http news autoua net ru news c65 conte

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
// качаем новости автомира
$url = "http://news.autoua.net/ru/news/c65/";
$content = file_get_contents($url);
// название
$title_arr = array();
preg_match_all("/ \2\p\x\;\"\> <a href=\"\/ru\/news\/(.*)\">(.*)<\/a>/U",$content,$title_arr);
//print_r($title_arr); //[2]
//краткое описание
//$des_arr = array();
//preg_match_all("/(0-9*)\.(0-9*)\.(0-9*) (0-9*)\:(0-9*)/U",$content,$des_arr);
//print_r($des_arr);
// даты
$time_arr = array();
preg_match_all("/[0-9]*\.[0-9]*\.[0-9]* [0-9:]* /U",$content,$time_arr);
//print_r($time_arr);
// рисунки
$image_arr = array();
preg_match_all("/<img src=\"http:\/\/news\.autoua\.net\/data\/library\/[0-9]*\/[0-9]*\/[0-9s]*\.jpg/U",$content,$image_arr);
foreach($image_arr as $index=> $value)
{
$image_arr[$index] = str_replace("<img src=\"","",$value);
}
//print_r($image_arr);
foreach($title_arr[2] as $index => $value)
{
$url = "http://news.autoua.net/ru/news/".$title_arr[1][$index];
$content = file_get_contents($url);
$text_arr = array();
preg_match_all("/<p>[0-9]*\.[0-9]*\.[0-9]* [0-9:]*<\/p>(.*)<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">/sU",$content,$text_arr);
//print_r($text_arr);
$image_name = time();
$text = preg_replace("/<\/a>/U","",$text_arr[1][0]);
$text = preg_replace("/<a(.*)>/U","",$text);
//$image_arr_s = array();
preg_match_all("/src=\"(.*)\"/U",$text,$image_arr_s);
//print_r($image_arr_s);
for($x=0; $x<10;$x++)
{
$text = preg_replace("/src=\"\/data(.*)\"/U","src=\"/news_img/".$image_name."_".$x.".jpg\"",$text,1);
}
//print $text;
$res = mysql_query("SELECT * FROM `avtonews2` WHERE `title`='".iconv("UTF-8","WINDOWS-1251",mysql_real_escape_string($value))."'");
if(mysql_num_rows($res)==0)
{
$query = "INSERT INTO `avtonews2` VALUE('','".iconv("UTF-8","WINDOWS-1251",mysql_real_escape_string($value))."','".iconv("UTF-8","WINDOWS-1251",trim(mysql_real_escape_string($text)))."','".$image_name."','".$time_arr[0][$index]."')";
mysql_query($query);
$id = mysql_insert_id();
@copy(str_replace("s.jpg","o.jpg",$image_arr[0][$index]),"news_img/news2".$image_name.".jpg");
foreach($image_arr_s[1] as $index=>$value)
{
@copy("http://news.autoua.net".$value,"/home/admin/www/vhosts/streetracing.uz.ua/httpdocs/news_img/".$image_name."_".$index.".jpg");
}
}
}