Last active
September 3, 2025 14:01
-
-
Save anboo/fec40c77711b7dc5aaae7dd299057012 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`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