Php 只捕获谷歌搜索结果中的网站链接
我有以下代码:Php 只捕获谷歌搜索结果中的网站链接,php,arrays,file-get-contents,Php,Arrays,File Get Contents,我有以下代码: $urls = file_get_contents('https://www.google.com/#q=test'); preg_match_all('/\b(?:(?:https?|http):\/\/|www\.)[-a-z]*.com/i', $urls, $content); $i = 10; while ( $i <= 50 ) { $i+= 10; $urls2 = file_get_contents('https://www.google.com/#
$urls = file_get_contents('https://www.google.com/#q=test');
preg_match_all('/\b(?:(?:https?|http):\/\/|www\.)[-a-z]*.com/i', $urls, $content);
$i = 10;
while ( $i <= 50 ) {
$i+= 10;
$urls2 = file_get_contents('https://www.google.com/#q=test&start=".$i."'); // pagination Google search Results
preg_match_all('/\b(?:(?:https?|http):\/\/|www\.)[-a-z]*.com/i', $urls2, $contentLoop);
$totalArray = array_push($content,$contentLoop);
}
print_r($totalArray);
$url=file\u get\u contents('https://www.google.com/#q=test');
preg_match_all('/\b(?:(?:https?| http):\/\/\/\ www\.)[-a-z]*.com/i',$url,$content);
$i=10;
而($iArray\u push仅用于将一个元素推送到数组末尾。您可以在此处使用两种可能的解决方案之一(两者都将数据保存到$content数组中):
使用数组合并
array_merge($content,$contentLoop);
循环$contentLoop
foreach($contentLoop as $item){
array_push($content,$item);
}
Array_push仅用于将一个元素推送到数组的末尾。您可以在此处使用两种可能的解决方案之一(都将数据保存到$content数组中):
使用数组合并
array_merge($content,$contentLoop);
循环$contentLoop
foreach($contentLoop as $item){
array_push($content,$item);
}
如果要将两个数组组合在一个数组中,则可以使用
array\u merge
-合并一个或多个数组
e、 g
请在此处查看官方文件:
如果要将两个数组组合在一个数组中,则可以使用
array\u merge
-合并一个或多个数组
e、 g
请在此处查看官方文件:
你似乎在试图刮取谷歌搜索结果。刮取是违反谷歌服务条款的。谷歌有一个web搜索api,但在2014年停止了。谷歌现在提供了一个自定义搜索api。你似乎在试图刮取谷歌搜索结果。刮取是违反谷歌服务条款的。谷歌有一个web服务earch api,但它在2014年停止使用。谷歌现在提供了一个自定义搜索api。array\u push返回int。尝试打印$content,而不是使用PHP简单html dom类从web获取内容。获取想要的数据要容易得多。array\u push返回int。尝试打印$content,而不是使用PHP简单html dom类从web获取内容网络。获取想要的数据要容易得多。