Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get contents of a div from a URL [duplicate]

Possible Duplicate:
How to implement a web scraper in PHP?
How to parse and process HTML with PHP?

I need to crawl through a page and get the contents of a particular div. I have php and javascript as my two main options. How can it be done?

like image 328
amit Avatar asked Feb 22 '23 15:02

amit


1 Answers

There are many ways to get the contents of an url:

First Method:

http://simplehtmldom.sourceforge.net/

 Simple HTML DOM Parser

Second Method :

<?php

  $contents = file_get_contents("http://www.url.com");
  $contents = strip_tags($contents, "<div>");
  preg_match_all("/<div/>(?:[^<]*)<\/div>/is", $contents, $file_contents);

?>

Third Method:

`You can use jquery like Selectors :` 

http://api.jquery.com/category/selectors/

like image 165
Sabari Avatar answered Mar 06 '23 00:03

Sabari