Ver Mensaje Individual
  #3 (permalink)  
Antiguo 07/02/2014, 12:10
tdcp
 
Fecha de Ingreso: febrero-2014
Ubicación: Madrid
Mensajes: 19
Antigüedad: 10 años, 2 meses
Puntos: 0
Respuesta: Extraer datos de otra web

Gracias ocp001a por tu respuesta... y disculpa si no he utilizado la herramienta, ahora lo hago. Pero díme, en qué ciclo incluirias tu el insert para que tome todos los datos?

Código PHP:
Ver original
  1. <?php
  2. require("phpsqlsearch_dbinfo.php");
  3. $connection=mysql_connect (localhost, $username, $password);
  4. if (!$connection) {
  5. die("Not connected : " . mysql_error());
  6. }
  7.  
  8. // Set the active mySQL database
  9. $db_selected = mysql_select_db($database, $connection);
  10. mysql_query("SET NAMES utf8");
  11. if (!$db_selected) {
  12. die ("Can\'t use db : " . mysql_error());
  13. }
  14.  
  15. $extrae = $_POST['url'];
  16. $provincias = $_POST['county'];
  17. $paises = $_POST['country'];
  18. // Use internal libxml errors -- turn on in production, off for debugging
  19. // Createa a new DomDocument object
  20. $dom = new DomDocument;
  21. // Load the HTML
  22. $dom->loadHTMLFile($extrae);
  23. // Create a new XPath object
  24. $xpath = new DomXPath($dom);
  25. //Query all <td> nodes containing specified class name
  26. $titulos = $xpath->query('//a[@class="url"]');
  27. $telefonos = $xpath->query('//p[@class="tel"]');
  28. $direcciones = $xpath->query('//span[@class="street-address"]');
  29. $ciudades = $xpath->query('//a[@class="locality"]');
  30. $lats = $xpath->query('//span[@class="latitude hidden"]');
  31. $lngs = $xpath->query('//span[@class="longitude hidden"]');
  32. // Set HTTP response header to text/html for debugging output
  33. header('Content-type: text/html; charset=utf-8');
  34. //Traverse the DOMNodeList object to output each DomNode's nodeValue
  35. foreach ($titulos as $titulo) {
  36. $name = ltrim($titulo->nodeValue);
  37. echo $name."<br>";
  38. }
  39. foreach ($direcciones as $direccion) {
  40. $address = $direccion->nodeValue;
  41. echo $address."<br>";
  42. }
  43. foreach ($ciudades as $ciudad) {
  44. $city = $ciudad->nodeValue;
  45. echo $city." ".$provincias." ".$paises."<br>";
  46. }
  47. foreach ($telefonos as $telefono) {
  48. $phone = $telefono->nodeValue;
  49. echo $phone."<br>";
  50. }
  51. foreach ($lats as $lat) {
  52. $latitud = $lat->nodeValue;
  53. echo $latitud."<br>";
  54. }
  55. foreach ($lngs as $lng) {
  56. $longitud = $lng->nodeValue;
  57. echo $longitud."<br>";
  58. }
  59. $sqlins = "INSERT INTO markersprueba (name, address, city, county, country, phone, lat, lng, fecAlta) ".
  60. "VALUES ('$name', '$address', '$city', '$provincias', '$paises', '$phone', '$latidud', '$longitud', CURDATE())";
  61. $resultins = mysql_query($sqlins) or die("No se ha podido insertar el log".mysql_error());
  62. ?>