我有一个来自另一个网站的iMDb-Scraper。它运行得很好,现在iMDb改变了它的html输出,正则表达式找不到海报了。我是正则表达式的新手,所以也许有人可以帮助我
就是这条线
$arr['poster'] = $this->match('/img_primary">.*?<img src="(.*?)".*?<\/td>/ms', $html, 1);和函数(可能不感兴趣)
function match_all($regex, $str, $i = 0) {
if(preg_match_all($regex, $str, $matches) === false)
return false;
else
return $matches[$i];下面是iMDb的特定HTML输出
<td rowspan="2" id="img_primary">
<div class="image">
<a href="/media/rm3465715968/tt1905041?ref_=tt_ov_i" >
<img height="317"
width="214"
alt="Fast and the Furious 6 (2013) Poster"
title="Fast and the Furious 6 (2013) Poster"
src="http://ia.media-imdb.com/images/M/MV5BMTM3NTg2NDQzOF5BMl5BanBnXkFtZTcwNjc2NzQzOQ@@._V1_SX214_.jpg"
itemprop="image" />
</a>
</div></td>有没有人可以修改正则表达式,让我拿回jpg?
发布于 2013-04-06 23:07:15
如果您将其更改为
'/img_primary">.*?<img.*?src="(.*?)".*?<\/td>/ms'这对我来说很有效:
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
$regexp = '/img_primary">.*?<img.*?src="(.*?)".*?<\/td>/ms';
$string = file_get_contents('test.html');
$matches = array();
preg_match_all($regexp,$string,$matches);
var_dump($matches);https://stackoverflow.com/questions/15852409
复制相似问题