首页 > 解决方案 > 如何检查Facebook帐户是否存在?

问题描述

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

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

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

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

请指教。

标签: phpfacebook

解决方案


在此处输入图像描述在此处输入图像描述下面的代码对我有用。但是我相信在做这个动作很多时间之后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- 用于 curl 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>';
}

推荐阅读