Crawling pages is a very common skill that is available in many languages. According to the official words, it is a web crawler. Here is a brief introduction to several PHP methods. I hope it can help everyone.
#1. The file() function mainly uses the file() function in the PHP language to directly obtain the file content. The language is simple and easy to use.
2. file_get_contents() function Note that when using it, the space is enabled. Before use, edit php.ini and set allow_url_fopen = On, so that it can be used. Use regular expressions when using it. Expression processing.
#3. fopen()->fread()->fclose() This is the most common in PHP The function is to open the file, read the file, close the file, there is not much to talk about.
4. Curl method This is awesome. It can be used under Linux and Windows. You need to install cul under Linux. For extension components, you need to modify php.ini under Windows and remove the semicolon in front of extension=php_curl.dll. It is not very difficult to use.
##5. fsockopen() function This is the socket mode. Whether the socket mode can be executed correctly also depends on the server settings. Relationship, you can check which communication protocols are enabled by the server through phpinfo.
6. Use plug-ins. There should be many plug-ins online. The snoopy plug-in was found online. There are If you are interested, you can study it. The usage is very simple and easy to get started.
The above content is for reference only!
Recommended video tutorial:
php video tutorialThe above is the detailed content of What are the methods for crawling Baidu content with PHP?. For more information, please follow other related articles on the PHP Chinese website!