Sina App Engine (SAE) Introductory Tutorial (8)-Saefetchurl use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.