Tags
PHP
Asked 2 years ago
28 Apr 2022
Views 323
jignesh

jignesh posted

how to Scrapp Website in PHP ?

i want to get some data from some sites that i use for learning and personal use but they don't provide API so I need to scrap that website with php , but dont know how to do it?
kiran

kiran
answered May 17 '22 00:00

to scrap the website , you need to get the HTML of the website pages
you can do it by curl functions or file_get_contents function

$html=file_get_contents("website url");

now use regular expression to find and matched element and get text or element detail

 preg_match_all('/src="([^"]+)"/',$html, $src_array, PREG_PATTERN_ORDER);
print_r($src_array);

suppose above code use regular expression to get src from all possible place from given html
you can try to get desired part of the website in PHP.
Post Answer