Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
页面完全加载后PHP文件获取内容_Php_Search Engine_File Get Contents - Fatal编程技术网

页面完全加载后PHP文件获取内容

页面完全加载后PHP文件获取内容,php,search-engine,file-get-contents,Php,Search Engine,File Get Contents,我正在创建一个网站,通过PHP文件获取内容功能来获取谷歌搜索结果。我已经问过了,他们告诉我应该在页面完全加载后再加载,但是我应该怎么做呢 我的问题是我想读出结果,如果我去google.com,每个标题都是H3。但当我加载时,每个标题都有一个唯一的类 我的代码 <?php require 'simple_html_dom.php'; echo ' <link rel="stylesheet" href="search.css" /> <link rel=

我正在创建一个网站,通过PHP文件获取内容功能来获取谷歌搜索结果。我已经问过了,他们告诉我应该在页面完全加载后再加载,但是我应该怎么做呢

我的问题是我想读出结果,如果我去google.com,每个标题都是H3。但当我加载时,每个标题都有一个唯一的类

我的代码

<?php

require 'simple_html_dom.php';

echo '
    <link rel="stylesheet" href="search.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
    <link rel="shortcut icon" type="image/png" href="favicon.png" />
    <body><div class="container">
';

$query = $_GET['q'];
if($query == '') {
    echo '<script type="text/javascript">window.location.href="index.html";</script>';
}

echo '<title>'.$query.' | SearchAda</title>';

echo '
    <form action="search.php" method="get">
        <a href="index.html"><h1 class="brand">SearchAda</h1></a>
        <div class="input-group">
            <input type="text" name="q" value="'.$query.'" placeholder="Typ uw zoekopdracht..." />
            <i class="fa fa-search"></i>
        </div>
    </form>
';

$url = 'https://www.google.com/search?q='.str_replace(' ','+',$query);

$doc = file_get_html($url);
echo $doc;

?>

一些屏幕截图 -
-

如果您只是下载一个网站的源代码并试图显示它,您将遇到问题。所有相关资源(
看起来像是您正在尝试为您的站点创建一个google搜索框。
如果是,我建议在这里进行谷歌搜索:

如果您想使用自己的代码(很难获得完整的解决方案):

我会给你一个工作的例子(不是一个完整的解决方案)

创建一个名为search_result.php的文件,并将以下代码粘贴到php标记中

require 'simple_html_dom.php';// I am not sure what this file is for :)

    $str = $_POST["q"]; 

      $url = "https://www.google.com/search?q=".str_replace(' ','+',$str);

    $result = file_get_contents($url);

    echo $result;
然后创建一个名为search.php的文件,并将以下代码粘贴到中:



google在
中有类,比如
google
是的,但是如果我使用file\u get\u contents,他不会返回H3-tag。如果你可以共享所有代码,有人可以帮我,你只共享html部分。这些都是我的代码!嗨,谢谢你的回答!但是我该怎么做呢?我知道这不是一个简单的方法,但一定有办法。有没有你有什么建议吗?@JeroenvanRensen试着从基本的php网络爬虫示例开始:看看这是否满足你的需要。对于Google来说,这应该足够了,但是如果你需要处理动态网站,你需要设置一个html呈现引擎。当我需要时,我使用了PhantomJS编辑:如果你需要中间层这里的解决方案是一个功能完整的PHP网络爬虫,我一直在寻找:嗨,我尝试了你的第一个链接。我创建了这段代码,不幸的是它也不起作用。它返回了一个空白网页`