【问题标题】:Scrape some text from another website without any url or special charecters从另一个网站上刮掉一些没有任何 url 或特殊字符的文本
【发布时间】:2016-05-08 11:02:30
【问题描述】:

我正在尝试学习一些代码的使用方法,并且我正在尝试抓取来自另一个站点的信息或一些文本到我的(仅供个人使用)。

好吧,例如我想从这个网站获取信息:

http://en.sratim.co.il/tt1150273/ROOM-(2015)/

我试图像这样的年份:

$year = explode( '<span class="yearpronobold">' , $content );
$year_end = explode("</span>" , $year[1] );

但结果是:

<a href="browse.php?uy=2015&amp;fy=2015">2015</a>

我只想要 2015 年的结果

也无法演员

演员:William H. Macy、Joan Allen (I)、Brie Larson、Cas Anvar、 Randal Edwards、Megan Park、Chantelle Chung

它给了我ARAY

谁能解释我该怎么做? 我试图在谷歌位上搜索它没有给出我正在搜索的正确结果。 谢谢你的帮助。

【问题讨论】:

  • 仅供参考,它是 scrape(和 scraperscrapingscraped)而不是 scrap

标签: php curl web


【解决方案1】:
include "simple_html_dom.php";

function doStrips($getString) {
    $getString  = strip_tags($getString);
    return $getString!="" ? $getString : "N/A";
}

$mainUrl= "http://en.sratim.co.il/";
$url    = "http://en.sratim.co.il/tt1150273/ROOM-(2015)/";
$ch     = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close($ch);

$html           = new simple_html_dom();
$html->load($server_output);
$releaseYear    = $html->find('.yearpronobold');
$actorDetails   = $html->find('a[itemprop="actors"]');
$directorDetails= $html->find('a[itemprop="director"]');
$getDuration    = $html->find('time[itemprop="duration"]');
$publishedDate  = $html->find('time[itemprop="datePublished"]');
$getGenre       = $html->find('span[itemprop="genre"]');
$getImage       = $html->find('img[itemprop="image"]');

//print_r($getImage);

echo "Release Year - ".doStrips($releaseYear[0]->children(0))."<br />";
echo "Actor(s) - ".doStrips(implode(", ",$actorDetails))."<br />";
echo "Director - ".doStrips(implode(", ",$directorDetails))."<br />";
echo "Duration - ".doStrips(implode(", ",$getDuration))."<br />";
echo "Published Date - ".doStrips(implode(", ",$publishedDate))."<br />";
echo "Genre - ".doStrips(implode(", ",$getGenre))."<br />";
echo "Image - <img src='".$mainUrl.$getImage[0]->attr["src"]."' /><br />";

首先,您需要检查您的服务器上是否启用了php_curlhttp://php.net/manual/en/curl.examples-basic.phpPHP_CURL上的教程。

这是我收到的输出..

【讨论】:

  • 它给了我outpot Wrong Input
  • sourceforge.net/projects/simplehtmldom 从这里下载 simple_html_dom.php..
  • 我下载了文件并将其上传到同一目录(如果我的文件)。但结果是输入错误i.imgur.com/UkOm8ga.png
  • 请发布您的代码,您所做的更改.. 这样我就可以清楚您的问题.. 谢谢..
  • 我没有更改任何代码只是复制粘贴...我应该更改 simple_html_dom 中的某些内容吗?来自新编辑的此处错误 [31-Jan-2016 13:16:08 America/Chicago] PHP Fatal error: Call to a member function children() on a non-object in /home/otzxuwui/public_html/sratim/index.php on line 30
猜你喜欢
  • 2017-10-09
  • 1970-01-01
  • 1970-01-01
  • 2016-10-28
  • 1970-01-01
  • 2011-10-28
  • 1970-01-01
  • 1970-01-01
  • 2020-04-10
相关资源
最近更新 更多