我想在html源代码中找到以下数据的匹配项:
<meta property="al:android:url" content="fb://profile/123123121123" />
使用preg_match_all()
;我不知道如何编写代码。
得到答案之后: preg_match_all('/] *)\“/',$ html,$ matches);
它不起作用,它返回一个空集。
这是我的代码:
$ret = array();
$matches = array();
// die();
$url = 'https://www.facebook.com/' . $fanpage_name;
// die($url);
$context = stream_context_create(array('http' => array('header' => 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0')));
for($a = 0; $a < $no_of_retries; $a++){
$like_html = file_get_contents($url, false, $context);
preg_match_all('/<meta property=\"al:android:url\" content=\"([^">]*)\"/', $like_html, $matches);
if(empty($matches[1])){
// failed to fetch any fans - convert returning array, cause it might be not empty
echo "test ";
return array_keys($ret);
}else{
// merge profiles as array keys so they will stay unique
$ret = array_merge($ret, array_flip($matches[1]));
}
// don't get banned as flooder
usleep($pause);
}
return array_keys($ret);
答案 0 :(得分:1)
如果您对“内容”属性感兴趣
preg_match_all('/<meta property=\"al:android:url\" content=\"([^">]*)\"/', $html, $matches);