dsc80135 2016-01-05 19:48
浏览 215

使用PHP Simple HTML DOM Parser从html中提取dom元素

I'm trying to extract links to the articles including the text, from this site using PHP Simple HTML DOM PARSER.

enter image description here

I want to extract all h2 tags for articles in the main page and I'm trying to do it this way:

    $html = file_get_html('http://www.winbeta.org');
    $articles = $html->getElementsByTagName('article');
    $a = null;

    foreach ($articles->find('h2') as $header) {
                $a[] = $header;


according to the manual it should first get all the content inside article tags then for each article extract the h2 and save in array. but instead it gives me :

enter image description here

EDIT enter image description here

  • 写回答



      相关推荐 更多相似问题


      • ¥15 实值特征权重向量和特征选择,多分类
      • ¥15 INVEST年产水量模块结果出处理
      • ¥15 Neo4j 不显示关系
      • ¥15 这段代码有什么bug
      • ¥15 pip默认安装位置修改不成功
      • ¥15 C++ inline、staitc、const三合一谁能讲通透
      • ¥15 关于pyqt5中QThread的问题
      • ¥20 STM32基于HAL库使用串口发送16进制数组
      • ¥15 OpenCV报错 You can enable it via 'OPENCV_IO_ENABLE_OPENEXR'
      • ¥15 AT89C51的程序问题