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

How to check if a facebook account exists?

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

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

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

它不会重定向到用户个人资料,而是打开一个显示 select 您的浏览器的页面。

请指教

enter 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);


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

要求:

<?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;
    }

?>