Answer the question
In order to leave comments, you need to log in
Parsing with Simple Html Dom, How to?
Good day. I'm trying to parse an archive of runs using the Simple Html Dom Parser library.
There is a site code:
<tr class="S2H"><td colspan="4" class="S2L">Футбол. До 17 лет. Чемпионат Европы. Элитный раунд</td><td class="bl">1</td><td>X</td><td class="br">2
</td></tr>
<tr><td>1</td><td>21.03 17:30</td><td class="S1L">Уэльс U17 - Швеция U17</td><td>0:1</td><td class="bl">32.00 / 30.81</td><td>28.00 / 26.00</td><td class="br">40.00 / 43.19
</td></tr>
<?
include 'simple_html_dom.php';
$html = file_get_html('http://sportsbet.com/list/ru/322/');
$res = $html->find('tr', 5);
echo $res;
?>
121.03 17:30Wales U17 - Sweden U170:132.00 / 30.8128.00 / 26.0040.00 / 43.19
Answer the question
In order to leave comments, you need to log in
<?php
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();
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_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 ".$this->url);
}
curl_close($cURLsession);
return $curlResult;
}
$url = "http://toto.fonsportsbet.com/list/ru/322/";
$content = getRemoteData($url, "", false);
// file_put_contents(__DIR__."\\footbal.html", $content);
// echo "Saved\n";
// $content = file_get_contents(__DIR__."\\footbal.html");
$regExpLigaWrapper =
"#(?<=<td colspan=4 class=S2L>)(.*?)(<td class=bl>)".
"(.*?)((?:<td colspan=4 class=S2L>)|(?:</table>))#si";
$regExpPlayWrapper =
"#<td>(\d{1,})<td>(.*?)<td class=S1L>(.*?)<td>".
"(.*?)<td(?:.*?)bl>(.*?)<td>(.*?)<(?:.*?)>(.*?)(?:<|$)#si";
preg_match_all($regExpLigaWrapper, $content, $ligaMatches, PREG_SET_ORDER);
foreach($ligaMatches as $ligaMatch)
{
echo "Liga: ".$ligaMatch[1]."\n****************************\n";
preg_match_all($regExpPlayWrapper, $ligaMatch[3], $playMatches, PREG_SET_ORDER);
foreach($playMatches as $playMatch)
{
echo
"id: ".$playMatch[1]."\n".
"Time: ".$playMatch[2]."\n".
"Name: ".$ligaMatch[1]."\t".$playMatch[3]."\n".
"Count: ".$playMatch[4]."\n".
"Class1: ".$playMatch[5]."\n".
"Class2: ".$playMatch[6]."\n".
"Class3: ".$playMatch[7]."\n".
"\n";
}
}
?>
I have achieved that the array contains the following data:
Football. Up to 17 years old. Europe championship. Elite round1X2
121.03 17:30Wales U17 - Sweden U170:132.00 / 30.8128.00 / 26.0040.00 / 43.19
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question