Use PHP's HTTP request library requests implement beauty picture wall, _php tutorial

Source: Internet
Author: User

Using PHP's HTTP request library requests implement beautiful picture wall,


Use Baidu's interface to get beautiful pictures, and the waterfall stream in the form of the display of their own pages.

GitHub Project Address: Https://github.com/CraryPrimitiveMan/pretty

The final effect is as follows:

Click on the beautiful channel of Baidu Pictures, http://image.baidu.com/channel?c=%E7%BE%8E%E5%A5%B3#%E7%BE%8E%E5%A5%B3

Open Chrome's Debugging tool or Firefox's Firebug tool, drag the scroll bar to the bottom, and you can see the following request in the network:

The parameters are as follows:

Through analysis, inference and validation of the meaning of the field, Col indicates that the channel, tag is all the beauty, or other tag (its content, such as), PN, from the first few pictures, RN said to get how many

The return value is as follows:

Analyze the content in IMGs, select the attributes you want, and I'm sure to use Shareurl.

This way we can use the PHP curl according to Baidu's API to get to beautiful pictures.

This can be written in PHP:

<?phprequire_once './requests/library/requests.php '; Requests::register_autoloader (); $page = $_get[' page '); $pageSize = ten; $options = Array (' Host ' = ' image.baidu.com '); $url = ' http://image.baidu.com/data/imgs?sort=0&pn= '. $page * $pageSize.     ' &rn= '. $pageSize. ' &col= Belle &tag= all &tag3=&p=channel&from=1 '; $response = Requests::get ($url, $options); echo $ Response->body;? >

One of the requests is a PHP HTTP request library, address: http://requests.ryanmccue.info/

One of the beauties can also be replaced by other channels.

After that, we went to show the pictures, using a waterfall stream plug-in implementation.

The final code was put on my GitHub, project address: Https://github.com/CraryPrimitiveMan/pretty

Only the parameters of Col on GitHub are photography ~ ~

Of course, the small partners can also be replaced by other harmonious resources, free to play.

http://www.bkjia.com/PHPjc/959102.html www.bkjia.com true http://www.bkjia.com/PHPjc/959102.html techarticle using PHP's HTTP request library requests implementation of beautiful pictures wall, using the interface of Baidu to get beautiful pictures, and waterfall flow in the form of display to their own pages. GitHub Project Address: H ...

  • Related Article

    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.