问题描述
我尝试了以下代码来从Google搜索结果中获取所有URL的列表。但是我可以找到带有说明的URL。我只想将URL作为列表。
<?php
include('simple_html_dom.php');
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch,CURLOPT_URL,$url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$query = "what is a car";
$url = 'http://www.google.com/search?q=' . urlencode($query) . '';
$scrape = file_get_contents_curl($url);
//gettype($scrape);
//echo $scrape;
$domResults = new simple_html_dom();
$domResults->load($scrape);
foreach ($domResults->find('a[href^=/url?q]') as $element) {
echo $element . '<br><br>';
}
?>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)