[英]PHP How to show results search google.com on site?
我想显示结果在google中找到框架。 查找查询
https://www.google.ru/search?newwindow=1&q=test%20speed
我使用代码:
<iframe src="https://www.google.ru/search?newwindow=1&q=test%20speed"
width="100%" scrolling="auto">
</iframe>
但我得到标题:
Refused to display 'https://www.google.ru/search?newwindow=1&q=test%20speed'
in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
正如我们所看到的,服务器google不能在框架中显示站点。
告诉我,显示结果如何在我的网站上找到google.com?
您可以使用他们的API,而不是iframe。 https://developers.google.com/custom-search/ (自定义搜索)或以下网址 : https : //developers.google.com/web-search/?hl=ru最新更好,因为您可以使用结果并根据需要打印,这是我在php上的示例:
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
. "q=" . urlencode($your_query) . "&userip=" . $_SERVER['REMOTE_ADDR'];
$jsonResult = file_get_contents($url);
$out = json_decode($jsonResult);
$out
的意志包含数组的结果,你可以foreach
它们:
foreach ($out->responseData->results as $record)
{
$this->_results['search'][] = array(
'title' => $record->title,
'description' => $record->content,
'sourceUrl' => $record->url,
'sourceShortUrl' => $record->visibleUrl,
);
}
在发布到Google
之前, &output=embed
添加到URL
的末尾。
<iframe src="https://www.google.ru/search?newwindow=1&q=test%20speed&output=embed"
width="100%" scrolling="auto">
</iframe>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.