如何从Facebook个人资料中获取属性属性?

问题描述 投票:1回答:1

我想从链接al:android:url获取特定属性https://www.facebook.com/tobiasz.mencfel

当前代码:String $link_id什么都没有显示。

我做到目前为止:

function file_get_contents_curl($url) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36');
  $html = curl_exec($ch);
  curl_close($ch);
  return $data;
}

$html = file_get_contents_curl("https://www.facebook.com/tobiasz.mencfel");

$doc = new DOMDocument();
@$doc->loadHTML($html);
$metas = $doc->getElementsByTagName('meta');

for ($i = 0; $i < $metas->length; $i++) {
  $meta = $metas->item($i);
  if ($meta->getAttribute('property') == 'al:android:url') {
    $link_id = $meta->getAttribute('content');
  }
}

// output should be: fb://profile/100025596917906
echo $link_id;

meta看起来如何:

<meta property="al:android:url" content="fb://profile/100025596917906" />
php html curl dom
1个回答
1
投票
//modify

return $data;

//to

return $html;

//result :  fb://profile/100025596917906
© www.soinside.com 2019 - 2024. All rights reserved.