Home > Backend Development > PHP Tutorial > javascript - php 抓取的页面如何处理可以只保留DOM结构,去掉CSS和JS?

javascript - php 抓取的页面如何处理可以只保留DOM结构,去掉CSS和JS?

WBOY
Release: 2016-06-06 20:50:47
Original
1218 people have browsed it

正则规则写好后,页面一旦有改变就要重新修改正则。
先提取页面的 DOM,有没有比较好的办法?

回复内容:

正则规则写好后,页面一旦有改变就要重新修改正则。
先提取页面的 DOM,有没有比较好的办法?

我想你需要的是 php 的 DOM 模块 ... 默认有安装不用担心 ...

因为不知道你的实际应用场景是什么 ... 给你写个简单的例子吧 ...

<?php /* i heard that you need DOM ..? */
$doc = new DOMDocument();

/* i wrote a simple page ... change it to a curl result ... */
$doc->loadHTML( <title>Sunyanzi's Test</title>

  <h1>Hello World</h1>
  <a href="http://segmentfault.com/" id="onlylink">Hey Welcome</a>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template