Created
December 7, 2016 06:56
-
-
Save talha08/63a7bc39ca893d676ea42c50a7ca2c66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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