I'm creating a website that scrapes Google search results with the PHP file_get_contents function. I've asked it here already, and they told me that I should load the page after it's fully loaded, but how should I do this?
My problem is that I want to read out the results, and if I go to google.com every title is a H3. But when I'm loading it in, every title has an unique class.
My code
<?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;
?>
` like `
– Dec 19 '19 at 18:23Google
`