简体   繁体   中英

How to parse HTML correctly with DOMDocument?


Lets say I have this type of HTML website:

stuff
<div id="123">
*HTML CODE I NEED*
</div>
stuff
<div id="234">
*HTML CODE I NEED*
</div>
more stuff

How can I extract HTML CODE I NEED from those div's, given that I know their IDs ?
Thank you!

You can get the nodes with DOMDocument::getElementById [docs] and the text content with the textContent [docs] property.

If you want the inner HTML of the nodes, you can call DOMDocument::saveHTML [docs] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM