Home >Backend Development >PHP Tutorial >Implementing beauty picture wall using PHP HTTP request library Requests_PHP tutorial

Implementing beauty picture wall using PHP HTTP request library Requests_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:03:521209browse

Using php's HTTP request library Requests to implement a beautiful girl picture wall

This article mainly introduces how to use php's HTTP request library Requests to implement a beautiful girl picture wall. It is very simple. Practical, friends in need can refer to it

Use Baidu’s interface to obtain pictures of beautiful women and display them on your own page in the form of waterfall flow.

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

The final effect is as follows:

使用php的HTTP请求的库Requests实现美女图片墙   帮客之家

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 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, we inferred and verified the meaning of the fields. col means channel, tag means all beauties, or other tags (the content is as shown below), pn means which picture to start from, and rn means How many pictures to get

The return value is as follows:

Analyze the content in imgs and select the attributes you want. I am sure to use shareUrl.

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

You can write this in php:

?

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=美女&tag=全部&tag3=&p=channel&from=1';

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

echo $response->body;

?>

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; ?>
Requests is a PHP HTTP request library, address: http://requests.ryanmccue.info/ The beauties can also be replaced with other channels. The next step is to display the pictures, which is implemented using a waterfall plug-in. The final code is placed on my Github, project address: https://github.com/CraryPrimitiveMan/pretty It’s just that the parameters of col on github are photography~~ Of course, friends can also switch to other harmonious resources and use them freely. http://www.bkjia.com/PHPjc/966923.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/966923.htmlTechArticleUsing php's HTTP request library Requests to implement a beauty picture wall. This article mainly introduces the use of php's HTTP request. The method of implementing the beauty picture wall in the library Requests is very simple and practical. All you need...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn