如何使用php刮取facebook页面

如何使用php刮取facebook页面,php,web-scraping,Php,Web Scraping,我想刮去facebook页面。我正在使用php <?php include('simple_html_dom.php'); $html = new simple_html_dom(); $html = file_get_html('http://www.facebook.com/'); // Find all images foreach($html->find('img') as $element) echo $element->src . '<

我想刮去facebook页面。我正在使用php

<?php

include('simple_html_dom.php');
$html = new simple_html_dom();  
$html = file_get_html('http://www.facebook.com/');
// Find all images 
foreach($html->find('img') as $element) 
       echo $element->src . '<br>';

// Find all links 
foreach($html->find('a') as $element) 
       echo $element->href . '<br>';
?>


但它给-

以上屏幕截图显示。-“请更新您的浏览器”。

我的浏览器是最新的。如果我用”http://www.google.com/“那么它工作得很好。我走对了吗?否则我就得试试别的。请推荐任何人。

我得到了答案:

Use this

 $c = curl_init('https://www.facebook.com');
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    //curl_setopt(... other options you want...)
    
    $html = curl_exec($c);
    
    if (curl_error($c))
        die(curl_error($c));
    
    // Get the status code
    $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
    
    curl_close($c);
<?php

include('simple_html_dom.php');
$html = new simple_html_dom();  
$options = array(
      'http'=>array(
        'method'=>"GET",
        'header'=>"Accept-language: en\r\n" .
                  "Cookie: foo=bar\r\n" .  // check function.stream-context-create on php.net
                  "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad 
      )
    );

    // fetch webpage content
    $context = stream_context_create($options);
 $html = file_get_html('https://www.facebook.com', false, $context);

// Find all images 
foreach($html->find('button') as $element) 
       echo $element. '<br>';
?>


但如果我将url替换为“https://www.facebook.com/techcrunch/about/". 它需要登录,为什么?

现在是空白屏幕。没有输出。simple_html_dom.phpsimple_html_dom.php中的内容包含大量代码,并且超出了限制。我该如何展示?你能推荐任何url来下载simple_html_dom.php吗?请检查我的答案。在答案中进一步提问不太可能有结果。仅供参考,这是刮(刮,刮,刮)而不是刮。”“报废”的意思是像垃圾一样扔掉。