可能的重复:
如何用PHP解析和处理HTML? https://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php
我已经尝试解决这个问题有一段时间了。我不仅尝试使用以下方式获取网页的内容file_get_contents($url)
还能够得出具体的数据。
我有兴趣抓取其内容的网页是克雷格列表 http://www.craigslist.org/about/sites。这只是一个例子。我想形成一系列带有区域和随附网站的状态,但我似乎找不到获取页面特定元素的方法。任何帮助将非常感激!
尝试使用 domdocument
$html = 'Assume this is html that you get';
$dom = new DOMDocument;
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('table'); // Sample to get table element
$rows = $tables->item(0)->getElementsByTagName('tr'); // sample to get rows of the table element
这是描述 http://php.net/manual/en/class.domdocument.php
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)