1

I'm using phpQuery to parse a site:

HTML example:

<div class="post" id="1232323">
   <div class="title">Example</div>
   <div class="text">texttexttext</div>
</div>

I can find the title and text but can't find id from div.post.

$document = phpQuery::newDocument(takeCode("example.com"));
$list_elements = $document->find('div.Post');
foreach ($list_elements as $element) 
{
   $pq = pq($element);
   $postTitle = $pq->find('div.Post')->attr('id'); //not found
   $postTitle = $pq->find('div.title')->text(); //found
   $postTitle = $pq->find('div.content')->text(); //found

}

How can I fix it?

3
  • Does $pq->attr('id') not give you that id? Commented Nov 24, 2016 at 18:53
  • thanks. $pq->attr('id') Commented Nov 25, 2016 at 3:35
  • Shall I turn this into an answer if it works for you? Commented Nov 25, 2016 at 8:18

2 Answers 2

1
foreach ($list_elements as $element) 
{
   $pq = pq($element);
   $postTitle = $pq->attr('id') //!
   $postTitle = $pq->find('div.title')->text(); //found
   $postTitle = $pq->find('div.content')->text(); //found

}
Sign up to request clarification or add additional context in comments.

Comments

0

To get the ID, use:

 $pq->attr('id');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.