Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch data from website using API [closed]

I have never used API before and this is the first work that I am going to use API to fetch data from another website to my website. Is there is any such API through which i can fetch data with PHP or Laravel5 etc.?

Actually i need to extract exchange rates from http://www.nrb.org.np/fxmexchangerate.php to my website. I should get the recent data i.e. updated data from this website.

How can i do this?

like image 892
Ranjeet Karki Avatar asked Feb 07 '26 11:02

Ranjeet Karki


1 Answers

API: application program interface.

If the site you're trying to collect data from doesn't provide an API then you'd have to find a way to collect the data yourself. If you're using PHP you can check this parser for a simple HTML DOM extractor.

They provide various examples on their site, check these and also check the structure of the site you're trying to get the content from and you should be fine:

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

// Find all images
foreach($html->find('img') as $element)
   echo $element->src . '<br>';

// Find all links
foreach($html->find('a') as $element)
   echo $element->href . '<br>'; 
like image 139
Juan Serrats Avatar answered Feb 09 '26 02:02

Juan Serrats



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!