Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
Cómo puedo obtener una imagen específica en un sitio web usando curl xpath en php

A través de este código puedo obtener el texto específico, pero mi problema es cómo puedo obtener la imagen específica en un sitio web a través de este código. Alguien puede ayudarme, estoy atascado en este punto.

 <?php ini_set('max_execution_time', 300); function news($url,$path){ $curl=curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $html=curl_exec($curl); if(!empty($curl)){ $thispage= new DOMDocument; libxml_use_internal_errors(true); $thispage->loadHTML($html); libxml_clear_errors(); $xpath=new DOMXPath($thispage); $status=$xpath->evaluate($path); return $status; } } $a= news('https://www.dawn.com/latest-news','string(/html/body/div[2]/div/main/div/div/div[1]/article[1]/h2/a)'); echo $a; ?>
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Suponiendo que desea que la imagen aparezca junto al primer título, el XPath es:

 function news($url,$path){ $curl=curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $html=curl_exec($curl); if(!empty($curl)){ $thispage= new DOMDocument; libxml_use_internal_errors(true); $thispage->loadHTML($html); libxml_clear_errors(); $xpath=new DOMXPath($thispage); $status=$xpath->evaluate($path); return $status; } } $a= news('https://www.dawn.com/latest-news','string(/html/body/div[2]/div/main/div/div/div[1]/article[1]/figure/div/a/img/@src)'); echo $a;
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda