我如何扫描 html 页面,以获取某个 div 中的文本?
问问题
2162 次
4 回答
2
最简单的方法是使用Simple HTML DOM parser
// Create a DOM object from a URL
$html = file_get_html('http://www.google.com/');
// Find all <div> which attribute id=foo
$ret = $html->find('div[id=foo]');
于 2009-12-28T20:28:48.863 回答
0
您可以按照其他人的建议使用内置功能,或者您可以尝试将 Simple HTML DOM Parser 实现为一个简单的 PHP 类和一些辅助函数。它支持 CSS 选择器样式的屏幕抓取(例如在 jQuery 中),可以处理无效的 HTML,甚至提供熟悉的界面来操作 DOM。
于 2010-01-03T09:05:55.890 回答
0
preg_match()
匹配您想要的子字符串或使用 dom/xml。
于 2009-12-28T20:29:19.033 回答