Simplexml可以用来通过HTML来窜? [英] Can simplexml be used to rifle through html?

查看:125
本文介绍了Simplexml可以用来通过HTML来窜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从表中获取数据而不使用正则表达式。我喜欢使用simplexml来解析RSS提要,并想知道它是否可以用来从另一个页面获取表格。



例如。用curl或简单的file_get_contents()来抓取页面;那么使用simplexml来抓取内容?

您可以使用 loadHTML 函数,然后通过 simplexml_import_dom

  $ html = file_get_contents('http://example.com/'); 
$ doc = new DOMDocument();
$ doc-> loadHTML($ html);
$ sxml = simplexml_import_dom($ doc);


I would like to grab data from a table without using regular expressions. I've enjoyed using simplexml for parsing RSS feeds and would like to know if it can be used to grab a table from another page.

Eg. Grab the page with curl or simply file_get_contents(); then use simplexml to grab contents?

解决方案

You can use the loadHTML function from the DOM module, and then import that DOM into SimpleXML via simplexml_import_dom:

$html = file_get_contents('http://example.com/');
$doc = new DOMDocument();
$doc->loadHTML($html);
$sxml = simplexml_import_dom($doc);

这篇关于Simplexml可以用来通过HTML来窜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆