Get specific html content from other site with PHP

こ雲淡風輕ζ 提交于 2019-12-10 12:25:36

问题


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>
...

回答1:


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!




回答2:


What you are asking for is called as web scrapping ,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,

  • HTML Parsing and Screen Scraping with the Simple HTML DOM Library
  • Beginning web page scraping with php

SO Posts:

  • HTML Scraping in Php

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




回答3:


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.



来源:https://stackoverflow.com/questions/15314781/get-specific-html-content-from-other-site-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!