Simple Scrapping in PHP With Simple HTML Dom

View: 1060    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: Web Development   Fields: Education - Schools

0 point/1 review File has been tested

Simple HTML DOM is a PHP5 library that allows easy scrapping in PHP. You can easily traverse HTML dom using jQuery like selectors. You can download the library from: http://simplehtmldom.sourceforge.net/

Introduction

Let’s see some examples:

 
// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');

// Find all images 
foreach($html->find('img') as $element) 
       echo $element->src . '
';

// Find all links 
foreach($html->find('a') as $element) 
       echo $element->href . '
';

Modifying the DOM is also quite easy. From the official docs:

// Create DOM from string
$html = str_get_html('
Hello
World
'); $html->find('div', 1)->class = 'bar'; $html->find('div[id=hello]', 0)->innertext = 'foo'; echo $html; // Output:
foo
World
 

Let’s see a real life example! How cool it would be if we could scrape slashdot with ease? Let’s try!

// Create DOM from URL
$html = file_get_html('http://slashdot.org/');

// Find all article blocks
foreach($html->find('div.article') as $article) {
    $item['title']     = $article->find('div.title', 0)->plaintext;
    $item['intro']    = $article->find('div.intro', 0)->plaintext;
    $item['details'] = $article->find('div.details', 0)->plaintext;
    $articles[] = $item;
}

print_r($articles);
 

Simple Scrapping in PHP With Simple HTML Dom

Simple Scrapping in PHP With Simple HTML Dom Posted on 26-03-2014  Simple HTML DOM is a PHP5 library that allows easy scrapping in PHP. You can easily traverse HTML dom using jQuery like selectors. You can download the library from: http://simplehtmldom.sourceforge.net/ 5/10 1060

Comment:

To comment you must be logged in members.

Files with category

  • JUnit 5 State Of The Union using java

    View: 602    Download: 0   Comment: 0   Author: none  

    JUnit 5 State Of The Union using java

    Category: Javascript
    Fields: Other

    2.25/2 review
    JUnit 5 has been under development for about 14 months now and the prototype is almost a year old. Time to summarize what happened so far, where the project stands, and where it’s going.

  • The CSS @supports Rule using AtoZ CSS Screencasts

    View: 486    Download: 0   Comment: 0   Author: none  

    The CSS @supports Rule using AtoZ CSS Screencasts

    Category: HTML-CSS template
    Fields: Other

    2.25/2 review
    This screencast is a part of our AtoZ CSS Series. You can find other entries to the series here.

  • How to Solving Common CSS Problems

    View: 511    Download: 0   Comment: 0   Author: none  

    How to Solving Common CSS Problems

    Category: HTML-CSS template
    Fields: Other

    2.5/2 review
    This article is a part of our AtoZ CSS Series. You can find other entries to the series here. You can view the full transcript and screencast for its corresponding video about the letter Q, thequotes property, here.

  • 11 Powerful Tips and Techniques in wordpress

    View: 455    Download: 0   Comment: 0   Author: none  

    11 Powerful Tips and Techniques in wordpress

    Category: WordPress template
    Fields: Other

    0/1 review
    Debugging is an essential skill for any developer. This tutorial will show you 11 powerful ways to debug WordPress and PHP errors.

  • MH Edition Lite Responsive WordPress Theme 2017 Free

    View: 610    Download: 6   Comment: 0   Author: none  

    MH Edition Lite Responsive WordPress Theme 2017 Free

    Category: WordPress template
    Fields: Other

    2.25/2 review
    MH Edition lite is a flexible and visually sophisticated WordPress theme for technology and news magazines. This magazine theme can transform your current WordPress website into a powerful and yet lightweight online magazine or dynamic news website...

  • Morning Monday Lite Responsive WordPress Theme Free

    View: 580    Download: 8   Comment: 0   Author: none  

    Morning Monday Lite Responsive WordPress Theme Free

    Category: WordPress template
    Fields: Other

    1.5/3 review
    Morning Monday Lite theme is designed for magazine with flexible layout. The theme is based on KOPATHEME layout manager technique that will let you flexibility choose layout options of every pages within your site.

  • How to Picking the Brains of Your Customers with Microsoft’s Text Analytics

    View: 3939    Download: 0   Comment: 0   Author: none  

    How to Picking the Brains of Your Customers with Microsoft’s Text Analytics

    Category: Php&mySql
    Fields: Other

    2.5/2 review
    With the explosion of machine learning services in recent years, it has become easier than ever for developers to create “smart apps”. In this article, I’ll introduce you to Microsoft’s offering for providing machine-learning capabilities to apps.

  • Getting Started with Dropwizard using java

    View: 691    Download: 0   Comment: 0   Author: none  

    Getting Started with Dropwizard using java

    Category: Javascript
    Fields: Other

    2.25/2 review
    Dropwizard is a framework for building RESTful web services in Java. In this tutorial we’re going to have a look at how to get started with developing a Dropwizard application by building a new service from scratch.

 

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd