This article mainly introduces a summary of commonly used methods for PHP to crawl web pages and parse HTML. This article is only a summary of how to achieve this The methods for the two requirements are summarized. We only introduce the methods, not how to implement them. Friends in need can refer to it
Overview
Crawler is a function that we often encounter when making programs. PHP has many open source crawler tools, such as snoopy. These open source crawler tools can usually help us complete most of the functions, but in some cases, we need to implement a crawler ourselves. This article explains how to implement crawlers in PHP a summary.
Main methods to implement crawler in PHP
1.file() function
2.file_get_contents() function
3.fopen()->fread()->fclose() method
4.curl method
5.fsockopen() function, socket mode
6. Use open source tools, such as: snoopy
Main ways for PHP to parse XML or HTML
1. Regular expression
2.PHP DOMDocument object
3. Plug-ins, such as: PHP Simple HTML DOM Parser
Summary
Here is a brief summary of the way PHP implements crawlers. There is a lot more content in this article. Later, I will make a summary of the way PHP parses HTML and XML.