What is Fetchurl?
Fetchurl is the SAE for developers to provide a distributed Web page crawl service, used to synchronize the crawling of HTTP pages, Fetchurl for the domestic network has been optimized, internal scheduling system, as far as possible to ensure that users quickly crawl to the target page. It is very simple to use Fetchurl on the SAE, just call a few simple functions in sae_std_lib.
Fetchurl is an alternative to when the SAE initially does not support curl, and the SAE is now fully compatible curl!
How to use Fetchurl?
For example, I want to crawl Baidu's webpage, then the code is as follows:
<? PHP $f New Saefetchurl (); $content $f->fetch (' http://www.baidu.com '); Var_dump ($content);? >
You can access the http://lazydemo.sinaapp.com/fetchurl/fetch_baidu.php to view the results.
Of course now that the SAE has fully supported curl, the above example can be completely rewritten with curl:
For a function on curl see: http://php.sinaapp.com/manual/zh/ref.curl.php
<? PHP // Create a new curl resource $ch = curl_init (); // set the URL and the corresponding options curl_setopt ($ch, Curlopt_url, "http://www.baidu.com/"); curl_setopt ($ch , Curlopt_header, 0); // fetch the URL and pass it to the browser curl_exec ($ch); // Close the Curl resource and release the system resource curl_close ($ch);? >
About SAE's support for Snoopy
Speaking of this aspect, we should all think of Snoopy, after testing, SAE for Snoopy is fully compatible, specific can be: about the SAE (Sina App Engine) Snoopy support issues You can also use Snoopy to overwrite this, see Code:
<? php // start test echo "I am alive!" include ("snoopy.class.php" $snoopy = new Snoopy; $url = "http://www.baidu.com" ; $snoopy ->fetch ( $url ); // get all the content echo $snoopy ->results; // show results ?
You can access the http://lazydemo.sinaapp.com/fetchurl/snoopy_baidu.php to view the results.
Setting a proxy operation is not supported
SAE Curl does not support curlopt_proxy option settings
This tutorial code package download
Http://lazydemo.sinaapp.com/fetchurl/fetchurl.zip
Sina App Engine (SAE) Introductory Tutorial (8)-Saefetchurl use