Use the php HTTP request library Requests to implement the beautiful pictures wall _ PHP Tutorial

Source: Internet
Author: User
Use the php HTTP request library Requests to implement the beautiful image Wall. This article describes how to use the php HTTP request library Requests to implement the beauty image Wall. it is very simple and practical, you need to use the php HTTP request library Requests to implement the beauty Picture Wall

This article mainly introduces how to use the php HTTP request library Requests to implement the beautiful image Wall. it is very simple and practical. For more information, see

Use Baidu's interface to get beautiful pictures and display them on your own page as a waterfall stream.

Github address: https://github.com/CraryPrimitiveMan/pretty

The final result is as follows:

Open Baidu pictures of beautiful channels, http://image.baidu.com/channel? C = % E7 % BE % 8E % E5 % A5 % B3 # % E7 % BE % 8E % E5 % A5 % B3

Open chrome debugging tool or firefox firebug tool, drag the scroll bar to the bottom, you can see the following request in the network:

The parameters are as follows:

Through analysis, we can infer and verify the meaning of the field. col indicates the channel, tag indicates all the beautiful women, or other tags (such as their content ), pn indicates the number of images starting from, and rn indicates the number of images obtained.

The return value is as follows:

Analyze the content in imgs and select the desired attributes. I am sure to use the desired URL.

In this way, we can use the PHP Curl to obtain beautiful pictures based on Baidu's API.

In php, you can write as follows:

?

1

2

3

4

5

6

7

8

9

10

11

Require_once './Requests/library/Requests. php ';

Requests: register_autoloader ();

$ Page = $ _ GET ['Page'];

$ PageSize = 10;

$ Options = array ('host' => 'image .baidu.com ');

$ Url = 'http: // image.baidu.com/data/imgs? Sort = 0 & pn = '. $ page * $ pageSize.

'& Rn ='. $ pageSize. '& col = beauty & tag = All & tag3 = & p = channel & from = 1 ';

$ Response = Requests: get ($ url, $ options );

Echo $ response-> body;

?>

Where Requests is a php http request Library, address: http://requests.ryanmccue.info/

The beauty can also be replaced with other channels.

The next step is to display images and use a waterfall stream plug-in.

The final code is put on my Github, Project address: https://github.com/CraryPrimitiveMan/pretty

The col parameter on github is photography ~~

Of course, you can also switch to other harmonious resources to make full use of them.

This article describes how to use the php HTTP request library Requests to implement the beautiful image Wall. it is very simple and practical...

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.