What is web scraping and how to scrape data in PHP?

Web scraping is a process of extracting data from a web document.

Two techniques used for scraping data from web documents are:

  • Document parsing For example, HTML or XML document is converted to DOM (Document Object Model). PHP offers DOM extension.

  • Regular expressions To scrape data from web document also regular expressions can be used.

Issue with scraping data from 3rd party websites is with copyrights if you don’t have permissions to use that data. Another disadvantage is keeping up with changes of the web document. Scraper must be adapted if that document changes. For these reasons it is better to check and use API of website where data needs to be scraped.

See also

GitHub OctocatFound a typo? Something wrong with this content? Just fork and edit it.

Content of this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. Code snippets in examples are published under the CC0 1.0 Universal (CC0 1.0). Thanks to all the contributors.