PHP简单的HTML DOM解析器找到LI元素

时间:2016-10-11 17:12:20

标签: php simple-html-dom

得到这样的结构:

<div class="info">
<ul class="info-fields">
<li style="display: none">
<span style="display:none" itemprop="brand">Text</span></li>
<li>Name: <h1 style="font-size: 14px;margin: 0px;display: inline;"><strong>Demo</strong></h1></li>
<li>Genre: <a href="url">text 1</a>, <a href="url">text 2</a></li>
<li>Country: <a href="url">text 3</a>, <a href="url">text 4</a></li>
<li>Duration: 02:53</li>
<li>Studio: <a href="url">Disney</a></li>
<li>Models: <a href="url" >text 5</a>, <a href="url">text 6</a></li>
</ul>
</div>

如何获得它&lt; a href =“url”&gt; text 1,&lt; a href =“url”&gt; text 2&lt; / A&GT;

由于

<li>Genre: <a href="url">text 1</a>, <a href="url">text 2</a></li>

我的代码

  $tagss = $html->find('ul.info-fields li:nth-child(3) a');
  $args_tags = array();   
  foreach($tagss as $element)
  {
     $tag1 = $element->plaintext;
     array_push($args_tags, $tag1);
   }

1 个答案:

答案 0 :(得分:0)

如果您的网址是变量,请尝试:

<li>Genre: <a href="<?=$url1?>">text 1</a>, <a href="<?=$url2?>">text 2</a></li>