It is possible to use Curl to pick up a certain ID or CLASS from a page

Asked

Viewed 200 times

0

I am studying php and I was looking at the Curl function and wanted to know if it is possible to take the content only of a certain ID of another page

example:

<div id="teste2">
     n pegar esse aqui
    </div>
<div id="teste">
 Pegar somente o conteúdo que esta aqui dentro
</div>
  • 1

    You can treat the return of Curl with the Domdocument class

  • It is not possible to use Curl to get only a certain part of the HTML code, which you can use Curl to get all HTML content and then parse the data you want.

  • @Anderson n understood what that would be like?

  • what language you are using shellscript?

  • @Anderson, I’m using php

  • Then you better use Domdocument as @Andersoncarloswoss mentioned a look here: http://php.net/manual/en/domdocument.getelementbyid.php

Show 1 more comment

1 answer

0


It won’t be too hard if you use something more appropriate to what you want to do.

You need a pound to help you do the interpretation of the DOM returned.

You can use Didom

https://github.com/Imangazaliev/DiDOM

use DiDom\Document;

$document = new Document('http://wp.test/teste.html', true);
$posts = $document->find('#teste2');
echo $posts[0]->text();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.