yanosh-k / duckduckgo
提供使用PHP进行DuckDuckGo搜索的函数(目前仅支持图片)
v1.0.0
2024-03-03 08:10 UTC
This package is auto-updated.
Last update: 2024-10-03 10:54:14 UTC
README
这是fastai的Python search_images_ddg()
函数的PHP版本。
它是他们Deep Learning for Coders书籍(可在Amazon上找到)的代码的一部分,该书中有一个名为search_images_ddg()
的函数。
您可以在这里了解更多关于为什么这个库存在的信息here。
如何使用
安装
使用composer
composer require yanosh-k/duckduckgo
用法
需要composer自动加载器
<?php
require_once('vendor/autoload.php'):
$searchResults = YanoshK\DuckDuckGo\SearchImagesDDG('brown dogs');
函数参数
此函数只接受两个参数:$term
和$maxImages
:SearchImagesDDG($term, $maxImages = 200)
。
$term
是要使用的搜索查询的字符串。
$maxImages
是一个介于1和1000之间的整数,告诉函数返回的最大结果数。
结果
当您调用SearchImagesDDG('SEARCH_TERM')
时,您将得到一个以下所示格式的结果数组。这是DDG在其内部API中使用的数据格式。大多数时候您需要image
参数值,它包含原始文件的URL。
[
[
'height' => 530,
'image' => 'https://static.semrush.com/blog/uploads/media/21/d9/21d991199d0e7392c20c38736f8fd32c/search-terms-sm.png',
'image_token' => 'b94f617df3182bb6c99361fb2c2d85c4e72722d46c06afe022e41d6730bb26c6',
'source' => 'Bing',
'thumbnail' => 'https://tse4.mm.bing.net/th?id=OIP.mzBL8Sb1e60zZlBY4Pi8kAHaD4&pid=Api',
'thumbnail_token' => '72056fe36342f76e10075153c3b62ae2814a694c5ffbdb23e1d4ad99fcd0eab9',
'title' => 'Search Terms: Definition & How to Use Them (with Examples)',
'url' => 'https://www.semrush.com/blog/search-terms/',
'width' => 1010,
],
[
'height' => 1250,
'image' => 'https://www.reliablesoft.net/wp-content/uploads/2019/06/people-also-ask-related-searches.png',
'image_token' => '0c4d1e495ef71ac644e8806bccf54d7f8de3f39a0cddfcf39ca305ddfc660380',
'source' => 'Bing',
'thumbnail' => 'https://tse1.mm.bing.net/th?id=OIP.6EvNQHr1FyZavhMUl2k_vwHaHG&pid=Api',
'thumbnail_token' => '653d830b8945e07ac649ff67ed5bdb70366662d29f690ea690211be1b21deb1f',
'title' => 'What are Search Terms? (With Examples)',
'url' => 'https://www.reliablesoft.net/what-are-search-terms/',
'width' => 1304,
],
[
'height' => 201,
'image' => 'https://static.semrush.com/blog/uploads/media/8a/09/8a09df80c31b1de73bc90c3c73e6889c/search-term.jpg',
'image_token' => '0db046ce4e19036d264ac5c6afeb59d16425eeb504dca37c0de7f216fc69707b',
'source' => 'Bing',
'thumbnail' => 'https://tse1.mm.bing.net/th?id=OIP.uozMlwbujR9P3JixU9cNTAAAAA&pid=Api',
'thumbnail_token' => '6334459b50b60891414a126835f438a88b31cf336937e0cf3003c3c1dd5c32b1',
'title' => 'Search Terms: Definition & How to Use Them (with Examples)',
'url' => 'https://www.semrush.com/blog/search-terms/',
'width' => 474,
],
[
'height' => 1334,
'image' => 'https://static.semrush.com/blog/uploads/media/02/2a/022ae1572f1ad01af34c62c93cd625b0/google-ads-search-terms-report.jpg',
'image_token' => '0a3620d50bd6c0f3d76e100a7b59e97f8aad46ba4d859c8e463d0d963eab50a8',
'source' => 'Bing',
'thumbnail' => 'https://tse3.mm.bing.net/th?id=OIP.eY0jXwtADz7z7ZTDjfIv6gHaJQ&pid=Api',
'thumbnail_token' => '9102854a16e33e9767a7690e0b5a8d7cb26e6dec8158be11a8991b407442f267',
'title' => 'Search Terms: Definition & How to Use Them (with Examples)',
'url' => 'https://www.semrush.com/blog/search-terms/',
'width' => 1068,
]