Home >Backend Development >PHP Tutorial >Quickly understand the techniques of crawling web content with PHP
How to correctly implement phpto capture web content? This problem is a bit difficult for friends who have not been exposed to PHP language for a long time. KekejieToday I will introduce you to the specific solution. First, I opened the extension=php_curl.dll function in php.ini in Cwindows, and then restarted apache. The following is the PHP I wrote to capture web content and capture the PHP information in Baidu: | /setURL Parameters curl_setopt($ch,CURLOPT_URL,"http: //http://www.baidu.com/s?wd=php"); //Require CURL to return data curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1); //Execute the request $result = curl_exec($ch) or die (curl_error()); //Get the returned result and display it echo $result; echo curl_error($ch); //Close CURL curl_close($ch); ?> But why? Why is there no response after PHP grabs the web content? There is no test text. If I put echo "test"; on the first line, it can be output. I guess the curl_init() function has not been run yet! See if there is CURL extension support in PHP's phpinfo()! Copy php_curl.dll to c:windows and c:windowssystem32 and restart apache and try again It is not the file php_curl.dll. Copy libeay32.dll and ssleay32.dll in the php directory to c:windowssystem32 and restart apache. For the sake of server security, allow_url_fopen is turned off. When the server allow_url_fopen = Off, file_get_contents cannot be used. It can only be used when it is set to ON. < ?php /* $getstr=file_get_contents("http://www. 163.com/weatherxml/54511.xml"); $qx=explode(""",strstr($getstr,"qx=")); $wd=explode(""",strstr($getstr,"wd=")); $qximg=explode(""",strstr($getstr,"qximg=")); $qximg_=explode(",",$qximg[1]); echo "Beijing ".$qx[1].""; echo $wd[1];*/ //echo "< img src='http://news. 163.com/img/ logo/".$qximg_[0]."'> < img src='http://news.163.com /img/logo/".$qximg_[1]."'>"; ?> The following example of PHP crawling web content is to obtain the 163 weather forecast through the curl_init function Remove the (;) in front of php.ini ( ;extension=php_curl.dll ) and save Copy php_curl.dll, libeay32.dll, ssleay32.dll to c:windowssystem32 and restart IIS. Apache is not installed < ?php Through the above study of PHP crawling web content, you can practice it yourself and deepen your understanding of it. More related information: http://www.kokojia.com/s64/ |