Skip to content

Instantly share code, notes, and snippets.

@anboo
Last active April 27, 2016 13:29
Show Gist options
  • Save anboo/fec40c77711b7dc5aaae7dd299057012 to your computer and use it in GitHub Desktop.
Save anboo/fec40c77711b7dc5aaae7dd299057012 to your computer and use it in GitHub Desktop.
`php
function getMobilePhone($href) {
$ch = curl_init('https://m.avito.ru'.$href);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FAILONERROR, 1);
curl_setopt ($ch, CURLOPT_ENCODING, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3');
curl_setopt( $ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_COOKIEFILE, 'cookie.txt');
$code = curl_exec($ch);
$html = str_get_html($code);
$link = $html->find('.action-show-number', 0)->href;
$ch = curl_init('https://m.avito.ru'.$link.'?async');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_REFERER, 'https://m.avito.ru'.$href);
$json = json_decode(curl_exec($ch));
$phone = preg_match('/8\ (.*)/', $json->phone, $matches);
return str_replace(['-', ' '], '', $matches[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment