我想在框架中显示谷歌搜索结果。查找查询
https://www.google.ru/search?newwindow=1&q=test%20speed
i use code:
<iframe src="https://www.google.ru/search?newwindow=1&q=test%20speed"
width="100%" scrolling="auto">
</iframe>
但是我得到header:
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.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,
);
}
将&output=embed
添加到URL
的末尾,然后再发布到Google
。
<iframe src="https://www.google.ru/search?newwindow=1&q=test%20speed&output=embed"
width="100%" scrolling="auto">
</iframe>