How to Make Simple Web Crawler Using PHP And MySQL

There are many ways to do this, and many languages you can build your spider or crawler in. PHP is one of the most popular and widely supported programming language for website-related programming. There are numerous libraries and tools for building crawlers and spiders using PHP. These tutorials show ways to build a crawler using this language. You may also like How to get latitude and longitude from google map using PHP and How to create zip file after upload file using PHP.

PHP Code

    $str = file_get_contents($main_url);

       $str = trim(preg_replace('/\s+/', ' ', $str)); 

    $b =$main_url;
    @$url = parse_url( $b );
    @$tags = get_meta_tags($url['scheme'].'://'.$url['host'] );

    $doc = new DOMDocument; 

    $items = $doc->getElementsByTagName('a'); 

    foreach ($items as $value) {
       $attrs = $value->attributes;
       $sec_url[] = $attrs->getNamedItem('href')->nodeValue;

   $all_links = implode(",", $sec_url);
   mysqli_query($con,"insert into webpage (main_url, title, description,link) values('$main_url','$title','$description','$all_links')");


Leave a Reply

Your email address will not be published. Required fields are marked *