【发布时间】:2019-12-19 18:00:00
【问题描述】:
我正在创建一个使用 PHP file_get_contents 函数抓取 Google 搜索结果的网站。我已经问了here,他们告诉我应该在页面完全加载后加载,但是我该怎么做呢?
我的问题是我想读出结果,如果我去 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 在
<h3>有课程,例如<h3 class="LC20lb">Google</h3> -
是的,但如果我使用 file_get_contents 他不会返回 H3 标记。
-
如果您可以共享所有代码,有人可以提供帮助,您只共享 html 部分
-
这些都是我的代码!
标签: php search-engine file-get-contents