我试图从某些网页的标记中抓取图像。这些网页都有幻灯片。它们的来源包含在页面上的JavaScript对象中。我想我需要get_file_contents(“http://www.example.com/page/1”);然后有一个可以输入短语(即“\”LargeUrl \“:\”“或”\“Description \”:\“”)的preg_match_all()函数,并获取字符串直到它碰到找到它的下一个引号。php正则表达式 - 刮来自javascript对象的图像
var photos = {};
photos['photo-391094'] = {"LargeUrl": "http://www.example.org/images/1.png","Description":"blah blah balh"};
photos['photo-391095'] = {"LargeUrl": "http://www.example.org/images/2.png","Description":"blah blah balh"};
photos['photo-391096'] = {"LargeUrl": "http://www.example.org/images/3.png","Description":"blah blah balh"};
我有这个功能,但它返回输入词组后的整行。我如何修改它以查找输入短语之后的所有内容,直到它找到它找到的下一个引号为止?还是我这样做是错的,还有更好的办法?
$page = file_get_contents("http://www.example.org/page/1");
$word = "\"LargeUrl\":\"";
if(preg_match_all("/(?<=$word)\S+/i", $page, $matches))
{
echo "<pre>";
print_r($matches);
echo "</pre>";
}
理想情况下,函数将返回数组像下面这样,如果我inputed“\” LargeUrl \“:\””
$matches[0] = "http://www.example.org/images/1.png";
$matches[1] = "http://www.example.org/images/2.png";
$matches[2] = "http://www.example.org/images/3.png";
你知道,最有可能是非法的? – zerkms 2012-07-18 02:53:06
他们是用户上传的图像。我将获得每个用户的许可。 – David 2012-07-18 03:01:33
你也检查过,这个网站还没有为此目的的API,对吧?这是什么网站? – wecsam 2012-07-18 03:21:13