Guest User

Untitled

a guest
Jul 9th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. <?php
  2.  
  3. function get_contents($url) {
  4. // We could just use file_get_contents but using curl makes it more future-proof (setting a timeout for example)
  5. $ch = curl_init($url);
  6.  
  7. curl_setopt_array($ch, array(CURLOPT_RETURNTRANSFER => true,));
  8.  
  9. $content = curl_exec($ch);
  10. curl_close($ch);
  11.  
  12. return $content;
  13. }
  14.  
  15. function scrape_main_page() {
  16. set_time_limit(300);
  17. libxml_use_internal_errors(true); // Prevent DOMDocument from spraying errors onto the page and hide those errors internally ;)
  18. $html = get_contents("http://lmvz.anofm.ro:8080/lmv/index2.jsp?judet=26");
  19.  
  20. $dom = new DOMDocument();
  21. $dom->loadHTML($html);
  22.  
  23. $xpath = new DOMXPath($dom);
  24. $results = $xpath->query("//table[@width=\"645\"]/tr");
  25.  
  26. $all = array();
  27. //var_dump($results);
  28. for ($i = 1; $i < $results->length; $i++) {
  29. $tr = $results->item($i);
  30.  
  31. $id = $tr->childNodes->item(0)->textContent;
  32. $requesturl = "http://lmvz.anofm.ro:8080/lmv/detalii.jsp?UNIQUEJVID=".urlencode($id)."&judet=26";
  33. $details = scrape_detail_page($requesturl);
  34.  
  35. $newObj = new stdClass();
  36. $newObj = $id;
  37. $all[] = $newObj;
  38.  
  39. }
  40.  
  41. foreach ($all as $xtr){
  42.  
  43. $urls[] = "http://lmvz.anofm.ro:8080/lmv/detalii.jsp?UNIQUEJVID=".$xtr."&judet=26";
  44.  
  45.  
  46. }
  47. return $urls;
  48. }
  49.  
  50. function scrape_detail_page($url) {
  51. }
  52.  
  53.  
  54. scrape_main_page();
Advertisement
Add Comment
Please, Sign In to add comment