Sharing tips on crawling web content with PHP_PHP Tutorial
How to implement it correctlyBut why does PHP not respond after crawling 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, restart apache and try again
It is not the file php_curl.dll, but 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.
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><</span><span> ?php /* </span></span></li><li><span>$</span><span class="attribute">getstr</span><span>=</span><span class="attribute-value">file_get_contents</span><span>("http://www.<br />163.com/weatherxml/54511.xml"); </span></li><li class="alt"><span>$</span><span class="attribute">qx</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($getstr,"</span><span class="attribute">qx</span><span>=")); </span></li><li><span>$</span><span class="attribute">wd</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($getstr,"</span><span class="attribute">wd</span><span>=")); </span></li><li class="alt"><span>$</span><span class="attribute">qximg</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($getstr,"</span><span class="attribute">qximg</span><span>=")); </span></li><li><span>$</span><span class="attribute">qximg_</span><span>=</span><span class="attribute-value">explode</span><span>(",",$qximg[1]); </span></li><li class="alt"><span>echo "北京 ".$qx[1].""; </span></li><li><span>echo $wd[1];*/ </span></li><li class="alt"><span>//echo "</span><span class="tag"><</span><span> </span><span class="tag-name">img</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">'http://news.<br />163.com/img/logo/".$qximg_[0]."'</span><span class="tag">><br></span><span class="tag"><</span><span> </span><span class="tag-name">img</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">'http://news.163.com<br />/img/logo/".$qximg_[1]."'</span><span class="tag">></span><span>"; </span></span></li> <li> <span class="tag">?></span><span> </span> </li> </ol>
The following example of PHP crawling web content is to obtain the 163 weather forecast through the curl_init function
Put php.ini ( ;extension=php_curl.dll ) Remove the previous (;) and save
Copy php_curl.dll, libeay32.dll, ssleay32.dll to c:windowssystem32 and restart IIS. Apache is not installed
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li><span>//初始化curl </span></li><li class="alt"><span>$</span><span class="attribute">ch</span><span> = </span><span class="attribute-value">curl_init</span><span>() or die (curl_error()); </span></li><li><span>//设置URL参数 </span></li><li class="alt"><span>curl_setopt($ch,CURLOPT_URL,"http:<br />//www.163.com/weatherxml/54511.xml"); </span></li><li><span>//要求CURL返回数据 </span></li><li class="alt"><span>curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); </span></li><li><span>//执行请求 </span></li><li class="alt"><span>$</span><span class="attribute">result</span><span> = </span><span class="attribute-value">curl_exec</span><span>($ch) or die (curl_error()); </span></li><li><span>//取得返回的结果,并显示 </span></li><li class="alt"><span>//echo $result; </span></li><li><span>// echo curl_error($ch); </span></li><li class="alt"><span>$</span><span class="attribute">qx</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($result,"</span><span class="attribute">qx</span><span>=")); </span></li><li><span>$</span><span class="attribute">wd</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($result,"</span><span class="attribute">wd</span><span>=")); </span></li><li class="alt"><span>$</span><span class="attribute">qximg</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($result,"</span><span class="attribute">qximg</span><span>=")); </span></li><li><span>$</span><span class="attribute">qximg_</span><span>=</span><span class="attribute-value">explode</span><span>(",",$qximg[1]); </span></li><li class="alt"><span>echo "北京 ".$qx[1]."</span><span class="tag"><</span><span> </span><span class="tag-name">br</span><span> </span><span class="tag">/></span><span>"; </span></span></li> <li><span>echo $wd[1]; </span></li> <li class="alt"><span>//关闭CURL </span></li> <li><span>curl_close($ch); </span></li> <li class="alt"> <span class="tag">?></span><span> </span> </li> </ol>
Through the above study of PHP crawling web content, you can practice it yourself and deepen your understanding of it.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Do you want to know how to display child categories on the parent category archive page? When you customize a classification archive page, you may need to do this to make it more useful to your visitors. In this article, we will show you how to easily display child categories on the parent category archive page. Why do subcategories appear on parent category archive page? By displaying all child categories on the parent category archive page, you can make them less generic and more useful to visitors. For example, if you run a WordPress blog about books and have a taxonomy called "Theme", you can add sub-taxonomy such as "novel", "non-fiction" so that your readers can

Understand the randomness of circular dependencies in Spring project startup. When developing Spring project, you may encounter randomness caused by circular dependencies at project startup...

Factors of rising virtual currency prices include: 1. Increased market demand, 2. Decreased supply, 3. Stimulated positive news, 4. Optimistic market sentiment, 5. Macroeconomic environment; Decline factors include: 1. Decreased market demand, 2. Increased supply, 3. Strike of negative news, 4. Pessimistic market sentiment, 5. Macroeconomic environment.

JDBC...

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Why is the return value empty when using RedisTemplate for batch query? When using RedisTemplate for batch query operations, you may encounter the returned results...

Discussion on the reasons why JavaScript cannot obtain user computer hardware information In daily programming, many developers will be curious about why JavaScript cannot be directly obtained...

Concordium: A public first-level blockchain platform that takes into account privacy and compliance is a public first-level blockchain platform. Its core lies in the clever integration of identity verification with privacy and regulatory compliance. Founded in 2018 by Lars Seier Christensen, the platform’s core technology embeds cryptographic identities at the protocol level of each transaction. This unique design ensures responsibility traceability while protecting user privacy, effectively solving the problem of conflicts between anonymity and regulatory requirements in the blockchain field. To alleviate this problem, Concordium utilizes Zero Knowledge Proof (ZKP) technology, allowing users to verify specific identity attributes without the need to disclose unnecessary personal information. This means that, despite every
