-1

I want to try and get the latest movie I checked on the IcheckMovies site and display it on my website. I don't know how, I've read about php_get_contents() and then getting an element but the specific element I want is rather deep in the DOM-structure. Its in a div in a div in a list in a ...

So, this is the link I want to get my content from: http://www.icheckmovies.com/profiles/robinwatchesmovies and I want to get the first title of the movie in the list.

Thanks so much in advance!

EDIT:

So using the file_get_contents() method

<?php
$html = file_get_contents('http://www.icheckmovies.com/profiles/robinwatchesmovies/');
echo $html;
?>

I got this html output. Now, I just need to get 'Smashed' so the content of the href link inside the h3 inside a div inside a div inside a list. This is where I don't know how to get it.

...
<div class="span-7">
<h2>Checks</h2>
<ol class="itemList">
<li class="listItem listItemSmall listItemMovie movie">
<div class="listImage listImageCover">
<a class="dvdCoverSmall" title="View detailed information on Smashed (2012)" href="/movies/smashed/"></a>
<div class="coverImage" style="background: url(/var/covers/small/10/1097928.jpg);"></div>
</div>
<h3>
<a title="View detailed information on Smashed (2012)" href="/movies/smashed/">Smashed</a>
</h3>
<span class="info">6 days ago</span>
</li>
<li class="listItem listItemSmall listItemMovie movie">
<li class="listItem listItemSmall listItemMovie movie">
</ol>
<span>
</div>
...
Robin
  • 47
  • 3
  • 5
  • Take a look at HttpRequest http://php.net/manual/en/class.httprequest.php – Brian Mar 09 '13 at 19:14
  • 1
    doesn't matter how deep in the html an ID element is...an element's ID should be unique to it. Post the code you tried using – CrayonViolent Mar 09 '13 at 19:14
  • Hi, this is rather vague, and you are basically already mentioning the most common solutions to this - `file_get_contents()` and parsing the DOM using a [HTML parser.](http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-xml-with-php/3577662#3577662) There are many many examples how to do this when e.g. Googling `Get specific html content from other site with PHP`. Is there a speficic aspect of this that you are stuck with? – Pekka Mar 09 '13 at 19:14
  • So sorry i'm not so clear about it. I've added the code, hope this helps. – Robin Mar 09 '13 at 19:56
  • can highlight the html you want by putting grave accent ` character around the text – DayTimeCoder Mar 09 '13 at 20:46

3 Answers3

1

follow steps to achieve this

STEP1:-

First get the contents using file_get_contents in a php file

ex: getcontent.php

<?php

echo file_get_contents("http://www.icheckmovies.com/movies/checked/?user=robinwatchesmovies ");

?>

STEP2:-

CALL the above script using ajax call and add the content to a visibility hidden field in the html.

ex:

$('#hidden_div').html(response);

html:-

<html>
<body>
<div id='hidden_div' style='visibility:hidden'>
</div>
</body>
</html>

STEP3:-

now extract the id what ever you want.

  • I don't need ajax I think or a hidden div. I've tried the file_get_contents() method though as you can see in my edited first post. Lots of thanks for the help though!! – Robin Mar 09 '13 at 19:57
  • hey @Robin what i mean is.. you passed first step you created a php file write? Now use ajax call to get the response of this php script in the html page and follow remaining steps $('#hidden_div h3 a').attr('href'); – Sri Tirupathi Raju Mar 09 '13 at 20:13
0

There are some libraries which could help you! One I've used for the same purpose, a long time ago, is this: http://simplehtmldom.sourceforge.net/

I hope it help you!

0

What you are asking for is called as web scraping ,I have done this a few months back, the process goes like this,

  • Make a HttpRequest to the site from which you need the content,check the php class for it
  • Use a DOM parse library for handling the downloaded page (it would be in html),simple HTLM DOM would be a good choice
  • Extract your required information

Here are some tutorials for you,

SO Posts:

And best of all Google is your friend just search for "PHP scraping"

DayTimeCoder
  • 4,294
  • 5
  • 38
  • 61