开发者

PHP Html Dom/Parser

开发者 https://www.devze.com 2023-03-19 21:48 出处:网络
i) I need to extract few elements from a html page using php. ii) Am using html dom parser. iii) I have been able to extract all **<a>**s, **<b>**s, **<li>**s, etc.

i) I need to extract few elements from a html page using php.

ii) Am using html dom parser.

iii) I have been able to extract all **<a>**s, **<b>**s, **<li>**s, etc.

iv) How should I be able to extract elements of the type/enclosed within

**<td c开发者_Go百科lass = ""><a href = "">ABC</a></td>**

Anything using href, i.e. property of href

Note: I need to extract ABC


This might not be the answer you are looking for but, I have worked with phpquery before and found it to be a great tool to do that kind of work.

http://code.google.com/p/phpquery/


You will not get the entire structure using the DOM Parser.

You should use getAttribute() method for that purpose. Check here

Here is a simple example also

$markup = file_get_contents($someplace);
$dom = new DomDocument();
$dom -> loadHTML($markup);
$tds = $dom -> getELementsByTagName("td");
foreach($tds as $td) {
    echo $td -> getAttribute("class");
}
0

精彩评论

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