Skip to content

Instantly share code, notes, and snippets.

@talha08
Created December 7, 2016 06:56
Show Gist options
  • Select an option

  • Save talha08/63a7bc39ca893d676ea42c50a7ca2c66 to your computer and use it in GitHub Desktop.

Select an option

Save talha08/63a7bc39ca893d676ea42c50a7ca2c66 to your computer and use it in GitHub Desktop.
<?php
$ch = curl_init("your-web-site");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$page = curl_exec($ch);
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($page);
libxml_clear_errors();
$xpath = new DOMXpath($dom);
$data = array();
//you need to learn xpath query
$table_rows = $xpath->query('//h2[@class="listing-item__title js-listing-title"]/a/@href');
foreach ($table_rows as $row => $p) {
foreach ($p->childNodes as $p) {
$data[$row][] = preg_replace('~[\r\n]+~', '', trim($p->nodeValue));
}
//avoid all empty
$data[$row] = array_values(array_filter($data[$row]));
}
echo '<pre>';
print_r($data);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment