如何检查 Facebook 帐户是否存在?

时间:2021-04-25 01:45:20

标签: php facebook

我正在尝试检查用户名是“abc.def”的 Facebook 用户是否存在。

echo file_get_contents("https://www.facebook.com/abc.def");

我的计划是使用 PHP DOM 库来读取页面上的文本。

它不会重定向到用户个人资料,而是打开一个页面,上面写着选择您的浏览器。

请指教。

2 个答案:

答案 0 :(得分:1)

enter image description hereenter image description here下面的代码对我有用。但我相信在做了这个动作之后,Facebook 可能会在很多时候屏蔽你的 ip。所以我建议你使用一些代理来让你的系统更好地工作并且不会停止。 还有一件事,我真的建议您自己测试代理,因为找到有效的代理会更容易。

$url = 'https://www.facebook.com/profileName/';
$ch = CURL_INIT();
CURL_SETOPT($ch, CURLOPT_URL, $url);
CURL_SETOPT($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
CURL_SETOPT($ch, CURLOPT_POST, false);
CURL_SETOPT($ch, CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5);
CURL_SETOPT($ch, CURLOPT_RETURNTRANSFER,True);
CURL_SETOPT($ch, CURLOPT_FOLLOWLOCATION,True);
CURL_SETOPT($ch, CURLOPT_ENCODING, 'gzip, deflate');
CURL_SETOPT($ch, CURLOPT_CONNECTTIMEOUT,30);
CURL_SETOPT($ch, CURLOPT_TIMEOUT,30); 
echo $result = CURL_EXEC($ch);

如果需要使用代理,可以这样使用:

$ip = '185.18.212.227';
$port = '3128';
$proxy = $ip.':'.$port;
/**
* If your proxy Require user or password
*/
$user = '';
$pwd ='';
$credential = $user.':'.$pwd;
$url = 'https://www.facebook.com/profileName/';
$ch = CURL_INIT();
CURL_SETOPT($ch, CURLOPT_URL, $url);
CURL_SETOPT($ch, CURLOPT_PROXY, $ip);
CURL_SETOPT($ch, CURLOPT_PROXYPORT, $port);
//CURL_SETOPT($ch, CURLOPT_PROXY, $proxy);//This one also can be used instead of the 2 lines above
//CURL_SETOPT($ch, CURLOPT_PROXYUSERPWD, $credential); In case of password is required to access
CURL_SETOPT($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
CURL_SETOPT($ch, CURLOPT_POST, false);
CURL_SETOPT($ch, CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5);
CURL_SETOPT($ch, CURLOPT_RETURNTRANSFER,True);
CURL_SETOPT($ch, CURLOPT_FOLLOWLOCATION,True);
CURL_SETOPT($ch, CURLOPT_ENCODING, 'gzip, deflate');
CURL_SETOPT($ch, CURLOPT_CONNECTTIMEOUT,30);
CURL_SETOPT($ch, CURLOPT_TIMEOUT,30); 
echo $result = CURL_EXEC($ch);

enter image description here


接下来的部分基本上会分为5个部分: 1- 我会在https://free-proxy-list.net/的第一页获取所有免费代理 2-将这些代理保存在一个数组中,键是proxyIp,值是proxyPorts 3- 通过从 google.com 抓取数据来检查这些代理是否真的有效,如果有效,我们会得到一些东西,如果无效,我们什么也得不到 4-保存正在工作的代理,以便使用它们来测试 Facebook 是否已经阻止了那些 IP,就像他们可能对您所做的那样 5- 用于卷曲 Facebook。

请记住,我正在做的事情需要一些时间,因为我要打开 30 到 40 个代理才能打开一页。因此,我建议您使用 CronJob 来免费从多个网站获取代理,并测试它们是否有效,您只需使用它们来抓取数据,这将是我认为的最佳方法。 另外要使用下一个脚本,你需要有 simple_html_dom,你可以在这里:https://simplehtmldom.sourceforge.io 我使用它只是为了收集我正在使用的代理。

ini_set("memory_limit",-1);
ini_set('MAX_EXECUTION_TIME', 0);

include 'simple_html_dom.php';


$goodProxy = array();

//1- Get all the free proxies in the first page of the https://free-proxy-list.net/
$url = 'https://free-proxy-list.net/';

$ch = CURL_INIT();
CURL_SETOPT($ch, CURLOPT_URL, $url);

CURL_SETOPT($ch, CURLOPT_FOLLOWLOCATION,True);
CURL_SETOPT($ch, CURLOPT_RETURNTRANSFER, TRUE);
CURL_SETOPT($ch, CURLOPT_CONNECTTIMEOUT,30);
CURL_SETOPT($ch, CURLOPT_TIMEOUT,30); 
$result = CURL_EXEC($ch);

$html =  new simple_html_dom();
$html ->load($result);
$table = $html->find('table',0);
$line = $table->find('tbody',0)->find('tr');

$ipProxyPorts = array();

foreach($line as $keys => $value){
    $ip = $value->find('td',0)->plaintext;
    $port = $value->find('td',1)->plaintext;
    $ipProxyPorts[$ip] = $port;
}
print_r($ipProxyPorts);
echo '<br><br><br><br><br><br>++++++++++++++++++++++++++++++++++++<br><br><br><br><br><br>';
//2- Got all the ips in the first page and they are set inside an array :$ipProxyPorts has the keys as the ip and the values as the ports 

//3- Next we will just check if those proxies are correct or if they can be used or not by scraping the first page of Google
//This part might take some time that is why it is important you set memory limit and max executing time to infinite on the top of the page
foreach($ipProxyPorts as $ip => $port){
    $url = 'https://www.google.com';
    $ch = CURL_INIT();
    CURL_SETOPT($ch, CURLOPT_URL, $url);
    CURL_SETOPT($ch, CURLOPT_PROXY, $ip);
    CURL_SETOPT($ch, CURLOPT_PROXYPORT, $port);
    CURL_SETOPT($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
    CURL_SETOPT($ch, CURLOPT_POST, false);
    CURL_SETOPT($ch, CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5);
    CURL_SETOPT($ch, CURLOPT_RETURNTRANSFER,True);
    CURL_SETOPT($ch, CURLOPT_FOLLOWLOCATION,True);
    CURL_SETOPT($ch, CURLOPT_ENCODING, 'gzip, deflate');
    CURL_SETOPT($ch, CURLOPT_CONNECTTIMEOUT,30);
    CURL_SETOPT($ch, CURLOPT_TIMEOUT,30); 
    
    echo $result = CURL_EXEC($ch);

    $textString = strip_tags($result);
    if(strlen($textString) > 20){
        $goodProxy[$ip] = $port;
    }
    
    curl_close($ch);
    echo '<hr>';
}

//4- Here are the proxies that are working right now and you could try to see if facebook already blocked them or not, but at least one of them must be ok to use I believe
echo ' "Proxy:port" that are working right now from the website https://free-proxy-list.net/';
print_r($goodProxy);

//5- Now you can use those proxies to see which one would not be blocked by facebook

foreach($goodProxy as $ip => $port){
    echo 'Proxy Used:'.$ip.':'.$port;
    $url = 'https://www.facebook.com/hygison/';
    $ch = CURL_INIT();
    CURL_SETOPT($ch, CURLOPT_URL, $url);
    CURL_SETOPT($ch, CURLOPT_PROXY, $ip);
    CURL_SETOPT($ch, CURLOPT_PROXYPORT, $port);
    CURL_SETOPT($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
    CURL_SETOPT($ch, CURLOPT_POST, false);
    CURL_SETOPT($ch, CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5);
    CURL_SETOPT($ch, CURLOPT_RETURNTRANSFER,True);
    CURL_SETOPT($ch, CURLOPT_FOLLOWLOCATION,True);
    CURL_SETOPT($ch, CURLOPT_ENCODING, 'gzip, deflate');
    CURL_SETOPT($ch, CURLOPT_CONNECTTIMEOUT,30);
    CURL_SETOPT($ch, CURLOPT_TIMEOUT,30); 
    echo $result = CURL_EXEC($ch);
    curl_close($ch);
    echo '<hr>';
}

答案 1 :(得分:0)

要求:

<?php


    $mySearchEngine = '----';//https://programmablesearchengine.google.com/cse/all
    $myGoogleApiKey = '----';//https://developers.google.com/custom-search/v1/overview

    //$queryExactTerm = 'If you want to use exact name';
    //$queryExactUrl = urlencode($queryExactTerm);

    $query = 'Name Of the person you want to search';
    $queryUrl = urlencode($query);
    
    
    $pg = 1;//If you do not find the name you want, you can loop and go to next pages, by changing this to 11,21,31...101
    
    $url = 'https://www.googleapis.com/customsearch/v1?';
    $url .= 'key='.$myGoogleApiKey;
    $url .= '&cx='.$mySearchEngine;
    $url .= '&q='.$queryUrl;
    $url .= '&start='.$pg;
    //$url .= '&exactTerms='.$queryExactUrl;
            

    $responseJson = curl_no_proxy($url);
    $responseArr = json_decode($responseJson, TRUE);
    
    if(isset($responseArr['items'])){
        foreach($responseArr['items'] as $key => $value){
            echo '<hr>';
            $title = $value['htmlTitle'];
            $link = $value['link'];
            
            echo $title.'<br>';
            echo $link.'<br>';

            //print_r($value);
            //You can get all information you want from here
        }
       
       
    }
   
    //If you want to see all the results 
    //foreach($responseArr as $key => $value){
        //echo '<hr>';
        //echo $key.'<br>';
        //print_r($value);
    //}
    
    function curl_no_proxy($url){
        $ch = CURL_INIT();
        CURL_SETOPT($ch, CURLOPT_URL, $url );
        CURL_SETOPT($ch, CURLOPT_POST, 0);
        CURL_SETOPT($ch, CURLOPT_RETURNTRANSFER,True);
        CURL_SETOPT($ch, CURLOPT_FOLLOWLOCATION,True);
        CURL_SETOPT($ch, CURLOPT_ENCODING, 'gzip, deflate');
        CURL_SETOPT($ch, CURLOPT_CONNECTTIMEOUT,30);
        CURL_SETOPT($ch, CURLOPT_TIMEOUT,30); 
        $result = CURL_EXEC($ch);
        CURL_CLOSE($ch);
        return $result;
    }

?>
相关问题