Use PHP's HTTP request library requests to implement _php example of beautiful picture wall

Source: Internet
Author: User

Use the interface of Baidu to get beautiful pictures, and in the form of waterfall flow to show their own pages.

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

The final effect is as follows:

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

Open the Chrome debugging tool or Firefox Firebug tool, drag the scroll bar to the bottom, and then network to see the following request:

The parameters are as follows:

Through analysis, infer and verify the meaning of the field, Col said that the channel, tag is all the beauty, but also can be other tag (its content as shown below), PN said from the first few pictures, RN said to get how many Zhang

The return value is as follows:

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

So we can use PHP curl according to Baidu's API to get beautiful pictures.

You can write this in PHP:

<?php
require_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;
? >

The requests is a library of PHP HTTP requests, address: http://requests.ryanmccue.info/

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

After that is to show the picture, using a waterfall flow plug-in implementation.

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

But the col parameter of GitHub is photography ~ ~

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

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.