在php抓取网页解析的过程中,涉及到了DOM这个东东,而自己对这块一无所知,所以借此机会,深入了解一下。
首先看一下wiki上dom的定义:(http://en.wikipedia.org/wiki/Document_Object_Model)
The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents.[
大意是说DOM=Document Object Model, 文件对象模型,是跨平台跨语言的,便于在HTML,XHTML, XML中的对象表示和交互。
是不是有点晕?
其实说白了, DOM就是把这些网页结构,递归解释成一个表示模型: 就是把网页转化为元素、属性和文本的树结构
<html> <head> <title>DOM Tutorial</title> </head> <body> <h1>DOM Lesson one</h1> <p>Hello world!</p> </body> </html>这段代码是从w3cschool上借过来的代码,它对应的dom是
--html 元素
----head 元素
------title: 元素, 文本: DOM Tutorial
----body元素
------h1 元素 文本: DOM Lession
------p 元素 文本: Hello World!