Scraping Data

jason06

New member
Hey There!

Would it be possible to scrape data without an API and display scraped data on my website? There are so many websites that do the same thing; they fetch data without an API and display it. It seems like cURL scrapes data without an API, but I'm not familiar with it. Can anyone here assist me?

Thanks!
 
You can use this function to get html:
Code:
function get_html(string $url): string {
    $ch = curl_init("http://www.example-webpage.com/file.html");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    $content = curl_exec($ch);
    curl_close($ch);
    return $content;
}

to get data from the retrieved html you can do it in 3 ways:
1. if it a valid html then you can use DomDocument: https://www.php.net/manual/en/class.domdocument.php
2. you can do it easily wyth preg_match
3. you can do it light with strpos/stripos and substr
 
Back
Top