`
pqcc
  • 浏览: 125203 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

php simplehtml

阅读更多


1. Scraping data with PHP Simple HTML DOM Parser

    foreach($html->find('a') as $element)   
         echo $element->href . '<br>';


2. Create DOM from string   
    $html = str_get_html('<div id="simple">Simple</div><div id="parser">Parser</div>');   
  
3. $html->find('div', 1)->class = 'bar';   
  
4. $html->find('div[id=simple]', 0)->innertext = 'Foo'; 

 


5. Match all 'A' tags that have the class attribute equal with 'l'   
   foreach($html->find('a[class=l]') as $key => $info)   
   {   
       echo ($key + 1).'. '.$info->plaintext."<br />\n";   
   } 
6. $url = 'http://www.google.com/search?hl=en&q=php&btnG=Search';
    // Create DOM from URL
   $html = file_get_html($url);
   // Match all 'A' tags that have the class attribute equal with 'l'
   foreach($html->find('a[class=l]') as $key => $info)
  {
       echo ($key + 1).'. '.$info->plaintext."<br />\n";
  }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics