我正在使用phpQuery解析一个站点:
HTML示例:
<div class="post" id="1232323">
<div class="title">Example</div>
<div class="text">texttexttext</div>
</div>我可以从div.post中找到标题和文本,但找不到id。
$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
}我怎么才能修复它?
发布于 2016-11-25 11:35:39
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
}发布于 2016-11-25 02:19:14
要获取ID,请使用:
$pq->attr('id');https://stackoverflow.com/questions/40792415
复制相似问题