开发者

Scraping <li> contents with PHP dom

how I could u开发者_开发问答se PHP dom screen scraping to pull the contents of an HTML tag called

<li style="margin-top:10px">

positioned in one of my pages?

I want to get all the contents of the <li> tag and display it as html code.


Use simpleXML and xpath. Supposing your HTML is all stored in the string $html, this may fit your need:

// Load your html from a file
$html = $file_get_contents("/path/to/page.html");
$xml = simplexml_load_string($html);

$li = $xml->xpath("//li[@style='margin-top:10px]");
echo $li->asXML();


$html='<li style="margin-top:10px">hello <b>World</b></li>';
if( preg_match('|<li style="margin-top:10px">(.*?)</li>|', $html, $matches) )
{
  $licontent = $matches[1];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜