Answer the question
In order to leave comments, you need to log in
How to parse data correctly?
Good day, friends.
For statistics, I want to collect data from the bookmaker's website in order to count them myself. I do it like this:
function getRemoteData($url, $argsArray, $ifPostRequest)
{
$userAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2414.0 Safari/537.36";
$cURLsession = curl_init();
$proxy = "47.89.185.76:3128"; // Прокси.
curl_setopt($cURLsession, CURLOPT_URL, $url);
curl_setopt($cURLsession, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURLsession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLsession, CURLOPT_USERAGENT, $userAgent);
//curl_setopt($cURLsession, CURLOPT_PROXY, "$proxy"); // Прокси.
curl_setopt($cURLsession, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($cURLsession, CURLOPT_CONNECTTIMEOUT, 30);
// curl_setopt($cURLsession, CURLOPT_REFERER, $url);
if($ifPostRequest)
{
curl_setopt($cURLsession, CURLOPT_POST, true);
curl_setopt($cURLsession, CURLOPT_POSTFIELDS, $argsArray);
curl_setopt($cURLsession, CURLOPT_HTTPHEADER,
array
(
"X-Requested-With: XMLHttpRequest"
));
}
if(($curlResult = curl_exec($cURLsession)) === false)
{
die("Error fetchind data: ".curl_error($cURLsession)." from ".$url);
}
curl_close($cURLsession);
return $curlResult;
}
$url = "https://fonbet.ru/#!/superexpress/info/982;
$content = getRemoteData($url, "", false);
$regExpLigaWrapper =
"#(?<=<div class=group-title col-12>)(.*?)(<div class=group-title col-12>)".
"(.*?)((?:<div class=group-title col-12>)|(?:</div>))#si";
$regExpPlayWrapper =
"#<div>(\d{1,})<div>(.*?)<div class=compact-middle-content>(.*?)<div>".
"(.*?)<div(?:.*?)bl>(.*?)<div>(.*?)<(?:.*?)>(.*?)(?:<|$)#si";
preg_match_all($regExpLigaWrapper, $content, $ligaMatches, PREG_SET_ORDER);
foreach($ligaMatches as $ligaMatch)
{
preg_match_all($regExpPlayWrapper, $ligaMatch[3], $playMatches, PREG_SET_ORDER);
foreach($playMatches as $playMatch)
{
echo
"id: ".$playMatch[1]."\n<br>".
"Time: ".$playMatch[2]."\n<br>".
"Name: ".$ligaMatch[1]."\t".$playMatch[3]."\n<br>".
"Count: ".$playMatch[4]."\n<br>".
"Class1: ".$playMatch[5]."\n<br>".
"Class2: ".$playMatch[6]."\n<br>".
"Class3: ".$playMatch[7]."\n<br>".
"\n *********** <br>";
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question