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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:50:47
Original
1270 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:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template