Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here is script how you do it with phpquery.
- <?php
- header("Content-type: text/csv");
- header("Content-Disposition: attachment; filename=file.csv");
- header("Pragma: no-cache");
- header("Expires: 0");
- include_once 'phpquery.php';
- $html = file_get_contents("http://www.tpos.co.uk/search-results.php?city=london&postcode=&submit=Search");
- $csv = "";
- $doc = phpQuery::newDocumentHTML($html);
- phpQuery::selectDocument($doc);
- foreach (pq("#member-list li") as $item){
- $fax=$phone=$website="";
- $name = trim(pq($item)->find(".col-1 strong")->eq(0)->html());
- $details = pq($item)->find("span.details")->html();
- $tmp = explode("<br>",$details);
- $address = trim($tmp[0]);
- foreach ($tmp as $key=>$t){
- if (strpos($t, "Fax")!==false){
- $fax = str_replace("Fax:","",trim(strip_tags($t)));
- }
- elseif (strpos($t, "Phone")!==false){
- $phone = str_replace("Phone:","",trim(strip_tags($t)));
- }
- elseif (strpos($t, "Website")!==false){
- $url = str_replace("Website:","",trim(strip_tags($t)));
- }
- }
- $csv .= "{$name};{$address};{$phone};{$fax};{$url}\n";
- }
- echo $csv;
- ?>
- It is impossible to get city from address because sometimes address includes extra commas.
- And here is the result file: https://mega.co.nz/#!nVIn2TJb!T9Q8IAOBnCxQeZ3byKTbSCb5Pz9WhbcvBlmwzMFq3Tk
- Doing everything for my first Thanks on BHW :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement