djey.official
Öğrenci
Html bir kaynaktaktan <h3> <img> <text> gibi degerleri cekmek istiyorum. Nasil yapabilirim?
<?php
function get_tag($website = null, $pattern = null)
{
$user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36';
$cookie_file = 'cookies.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $website);
curl_setopt($ch, CURLOPT_REFERER, $website);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);
$html = curl_exec($ch); // Sitenin HTML kodu artık bu değişkende.
curl_close($ch);
if(preg_match_all($pattern, $html, $matches))
{
return $matches[1];
}
}
$h3 = get_tag('https://forum.shiftdelete.net/threads/html-den-tag-secerek-veri-cekmek-yardim-edin.453043/#post-3867934', "#<h3>(.*?)</h3>#si");
echo $h3[0] . '<br>' . $h3[1];
?>
Javascript ile çok daha kolay şekilde dizi olarak alamaz mıyız?
var h = document.getElementsByTagName("h1");
h[0].innerHtml;