Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda