PHP Curl Sonucunu Ayrıştırma
Curl eklentisi ile bir başka sitenin verilerini ayrıştırma işleminde kullanılan yöntemler
getElementById Örnekleri
$domObject= new DOMDocument();
$domObject->loadHTML($source);//put your complete source html string here
$result=$domObject->getElementById("test");//this will output DOMElement Object
print_r($result->nodeValue);
$domObject->loadHTML($source);//put your complete source html string here
$result=$domObject->getElementById("test");//this will output DOMElement Object
print_r($result->nodeValue);
$doc->getElementById('php-basics')->tagName
Özellik Var Mı?
if($node->item(0)->hasAttribute('src')) {
$firstimage = $node->item(0)->getAttribute('src');
} else {
$firstimage = "";
}
$firstimage = $node->item(0)->getAttribute('src');
} else {
$firstimage = "";
}
Tagın İsmini Almak
$ATagi = $Html->getElementById('product_image_zoom')->tagName;
Tag Var Mı?
$ATagi = $Html->getElementById('image_zoom');
if($ATagi) {
$Id = $ATagi->getAttribute('href');
}
if($ATagi) {
$Id = $ATagi->getAttribute('href');
}
Örnek
<div class="list_price">
<span class="text">Liste Fiyatı:</span>
<span class="value"><span class="TL"></span> 18,52</span>
</div>
<span class="text">Liste Fiyatı:</span>
<span class="value"><span class="TL"></span> 18,52</span>
</div>
$DivTagi->getElementsByTagName('span')->item(1)->textContent
Sonuç 18,52 olcaktır.
Örnek
<div class="big">
<span class="before"></span>
<div class="middle">
<span class="text"><span class="TL"></span> 14,<small>81</small></span>
</div>
<span class="after"></span>
</div>
<span class="before"></span>
<div class="middle">
<span class="text"><span class="TL"></span> 14,<small>81</small></span>
</div>
<span class="after"></span>
</div>
$HedefSpanIcerigi = $Html->getElementsByTagName('div')->item(0)->getElementsByTagName('div')->item(0)->getElementsByTagName('span')->item(0)->textContent;
Örnek
<td valign="top">
<span style="font-family: Verdana; font-size:10pt;">
<a href="http://www.dijitalders.com">dijitalders</a>
</span>
</td>
<span style="font-family: Verdana; font-size:10pt;">
<a href="http://www.dijitalders.com">dijitalders</a>
</span>
</td>
$BulunanTaglar = 0;
$SpanTaglari = $Html->getelementsbytagname('span');
foreach ($SpanTaglari as $SpanTagi) {
if ($SpanTagi->getAttribute('style') == 'font-family: Verdana; font-size:10pt;') {
$BulunanTaglar++;
if ($BulunanTaglar == 1) {
$this->BulunanDegerler['UrunAdi'] = $SpanTagi->childNodes[0]->C14N();
break;
}
}
}
$SpanTaglari = $Html->getelementsbytagname('span');
foreach ($SpanTaglari as $SpanTagi) {
if ($SpanTagi->getAttribute('style') == 'font-family: Verdana; font-size:10pt;') {
$BulunanTaglar++;
if ($BulunanTaglar == 1) {
$this->BulunanDegerler['UrunAdi'] = $SpanTagi->childNodes[0]->C14N();
break;
}
}
}
Sonuç: <a href="http://www.dijitalders.com">dijitalders</a>
Örnek
$Html = new DOMDocument();
$Html->loadHTML($KiboSayfasi);
$SpanTaglari = $Html->getelementsbytagname('span');
foreach ($SpanTaglari as $SpanTagi) {
$Style = $SpanTagi->getAttribute('style');
if ($Style == 'font-family: Verdana; font-size:9pt;') {
echo $SpanTagi->textContent;
break;
}
}
$Html->loadHTML($KiboSayfasi);
$SpanTaglari = $Html->getelementsbytagname('span');
foreach ($SpanTaglari as $SpanTagi) {
$Style = $SpanTagi->getAttribute('style');
if ($Style == 'font-family: Verdana; font-size:9pt;') {
echo $SpanTagi->textContent;
break;
}
}
Örnek
$html = curl_exec($ch);
curl_close($ch);
preg_match('~<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="(.*?)" />~', $html, $viewstate);
preg_match('~<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.*?)" />~', $html, $eventValidation);
echo $viewstate[1];
echo $eventValidation[1];
curl_close($ch);
preg_match('~<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="(.*?)" />~', $html, $viewstate);
preg_match('~<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.*?)" />~', $html, $eventValidation);
echo $viewstate[1];
echo $eventValidation[1];
Kaynak
Yorumunuzu Ekleyin