Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write this crawler in php?

I need to create a php script.

The idea is very simple:

When I send a link of a blogpost to this php script, then the webpage is crawled and the first image with the title page are saved on my server.

What PHP function I have to use for this crawler ?

like image 722
xRobot Avatar asked Aug 02 '26 20:08

xRobot


2 Answers

Use PHP Simple HTML DOM Parser

// Create DOM from URL
$html = file_get_html('http://www.example.com/');

// Find all images
$images = array(); 
foreach($html->find('img') as $element) {
       $images[] = $element->src;
} 

Now $images array have images links of given webpage. Now you can store your desired image in database.

like image 159
Naveed Avatar answered Aug 07 '26 13:08

Naveed


HTML Parser: HTMLSQL

Features: you can get external html file, http or ftp link and parse content.

like image 45
Eugen Avatar answered Aug 07 '26 11:08

Eugen