使用PHP从其他网站获取特定的html内容 [英] Get specific html content from other site with PHP

查看:100
本文介绍了使用PHP从其他网站获取特定的html内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试获取我在IcheckMovies网站上检查的最新电影,并将其显示在我的网站上。我不知道如何,我已经阅读了关于php_get_contents(),然后获取一个元素,但我想要的具体元素是相当深入的DOM结构。它在一个div中的div在一个列表中的一个...



所以,这是我想要获取我的内容的链接: http://www.icheckmovies.com/profiles/robinwatchesmovies ,我想在列表中获得电影的第一个标题



非常感谢!



编辑:



所以使用file_get_contents()方法

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

我有这个html输出。现在,我只需要得到'Smashed',所以href内部的h3内部的一个div里面的一个div里面的列表。这是我不知道如何得到它的地方。

  ... 
< div class =跨度-7\" >
< h2>检查< / h2>
< ol class =itemList>
< li class =listItem listItemSmall listItemMovie movie>
< div class =listImage listImageCover>
< a class =dvdCoverSmalltitle =查看Smashed(2012)的详细信息href =/ movies / smashed />< / a>
< div class =coverImagestyle =background:url(/var/covers/small/10/1097928.jpg);>< / div>
< / div>
< h3>
< a title =查看有关捣毁(2012)的详细信息href =/ movies / smashed />捣毁< / a>
< / h3>
< span class =info> 6天前< / span>
< / li>
< li class =listItem listItemSmall listItemMovie movie>
< li class =listItem listItemSmall listItemMovie movie>
< / ol>
< span>
< / div>
...


解决方案

这个



STEP1: -



首先使用php文件中的file_get_contents获取内容



ex:getcontent.php

 <?php 

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

?>

STEP2: -



脚本使用ajax调用,并将内容添加到html中的可见性隐藏字段。



ex:



<$ p $ 。p> $( '#hidden_​​div')的HTML(响应);

html: -

 < HTML> 
< body>
< div id ='hidden_​​div'style ='visibility:hidden'>
< / div>
< / body>
< / html>

STEP3: -



现在提取id你想要什么。


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

解决方案

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.

这篇关于使用PHP从其他网站获取特定的html内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆