我正在嘗試制作一個javascript函式,當被呼叫時,它將從文本框中獲取用戶輸入并使用該輸入搜索谷歌影像并從出現的第一張影像中獲取鏈接,然后將其設定為影像的來源(我尚未決定影像的 ID),任何有關如何執行此操作的建議都會非常有用
uj5u.com熱心網友回復:
您可以使用此 Node 庫輕松完成:https ://www.npmjs.com/package/image-search-google 以下是 JS 代碼示例:
const imageSearch = require('image-search-google');
const client = new imageSearch('CSE ID', 'API KEY');
const options = {page:1};
client.search('APJ Abdul kalam', options)
.then(images => {
/*
[{
'url': item.link,
'thumbnail':item.image.thumbnailLink,
'snippet':item.title,
'context': item.image.contextLink
}]
*/
})
.catch(error => console.log(error););
// search for certain size
client.search('Mahatma Gandhi', {size: 'large'});
// search for certain type
client.search('Indira Gandhi', {type: 'face'});
使用屬性 url,您可以使用此 URL 生成一個標簽。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/451301.html
標籤:javascript html jQuery css 图片
