Web Scraping With PHP

//Making User agent just like google which helps the browser to say which site visit
$options = array('http'=>array('method'=>"GET",'headers'=>"User-Agent: Nir003"));
$context = stream_context_create($options);


// allows you to parse html pages
$doc = new DOMDocument();


// load full page in $doc variable
//download the page
@$doc->loadHTML(@file_get_contents($url,false,$context)); 
Thats all! your page load into $doc as object
😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍
Now the data is yours ;)
now do what ever you want with this scraped data.
Like here i separate title from $doc :

$title = $doc->getElementsByTagName("title");
$title = $title->item(0)->nodeValue;
echo $title;      
// <title> Youtube(nodeValue) </title>

মন্তব্যসমূহ

একটি মন্তব্য পোস্ট করুন

এই ব্লগটি থেকে জনপ্রিয় পোস্টগুলি

SEO [Search Engine Optimization ] (সার্চ ইঞ্জিন অপ্টিমাইজেশান)