Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("../simple_html_dom/simple_html_dom.php");
- include("config.php");
- include("mysql.php");
- include("parser.php");
- $perPage = 3;
- function GetFeedJSON($url, $type, $action, $p) {
- $headers = [
- "Accept: application/json, text/javascript, */*; q=0.01",
- "Accept-Encoding: gzip, deflate",
- "Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
- "Host: www.eip.ru",
- "Origin: http://www.eip.ru",
- "Referer: $url",
- "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36",
- ];
- $file = tempnam("", "yparse_");
- $ch = curl_init("$url?type=$type&action=$action&page=$p");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1) ;
- //curl_setopt($ch, CURLOPT_VERBOSE, true);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $file);
- $data = curl_exec($ch);
- preg_match_all('/name\=\"\_csrf\"\s*value\=\"(.+\=\=)\"/ium', $data, $res);
- $_csrf = $res[1][0];
- $fields =
- 'address=&'.
- 'price_from=&'.
- 'price_to=&'.
- 'num=&'.
- 'square_from=&'.
- 'square_to=&'.
- 'square_living_from=&'.
- 'square_living_to=&'.
- 'square_kitchen_from=&'.
- 'square_kitchen_to=&'.
- 'subject=&'.
- 'house_type=&'.
- 'san_uzel=&'.
- 'floor_from=&'.
- 'floor_to=&'.
- 'view=&'.
- 'region_id=0&'.
- "page=$p&".
- 'order_by=&'.
- 'user_id=&'.
- 'order_dir=&'.
- "_csrf=$_csrf&".
- 'json=1'
- ;
- rtrim($fields, '&');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1) ;
- //curl_setopt($ch, CURLOPT_VERBOSE, true);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $file);
- $data = curl_exec($ch);
- print_r(json_decode($data)->data);
- exit();
- }
- function ParseFeed($url){
- $html = file_get_html($url);
- $urls = [];
- foreach ($html->find("tr td[class=address_table] a") as $a) {
- array_push($urls, "http://www.eip.ru" . $a->href);
- }
- return $urls;
- }
- function ParseAid($url, $DBtype){
- $html = file_get_html($url);
- return [
- 'phone' => $html->find("i[class=phone]", 0)->plaintext,
- 'description' => $html->find("div[class=description]", 0)->plaintext,
- 'price' => $html->find("div[class=price_block] div div", 0)->plaintext,
- 'street' => $html->find("h1", 0)->plaintext,
- 'type' => $DBtype,
- 'source' => $url
- ];
- }
- function GetAidFromJSON($json, $DBtype){
- return [
- 'phone' => $json->phone,
- 'description' => $json->description,
- 'price' => $json->price,
- 'street' => $json->address,
- 'type' => $DBtype,
- 'source' => "http://www.eip.ru/moskva/detail/" . $json->id
- ];
- }
- function ParserDriver($table, $DBtype, $feedUrl){
- global $perPage;
- $urls = ParseFeed($feedUrl);
- $count = 0;
- foreach ($urls as $url) {
- $count++;
- if ($count > $perPage) break;
- $aid = ParseAid($url, $DBtype);
- InsertToPTable($table, $aid);
- }
- }
- /*ParserDriver('aidp', 2, "http://www.eip.ru/moskva/flats/sale");
- ParserDriver('aidp', 1, "http://www.eip.ru/moskva/flats/rent");
- ParserDriver('commercep', 2, "http://www.eip.ru/moskva/offices/sale");
- ParserDriver('commercep', 1, "http://www.eip.ru/moskva/offices/rent");
- ParseFeedCurl('http://www.eip.ru/moskva/flats/rent');*/
- print_r(GetFeedJSON('http://www.eip.ru/moskva/flats/rent', 'flats', 'rent', 8));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement