簡體   English   中英

將請求發送到具有驗證碼的不同站點上的多種表單

[英]Send requests to multiple forms on different sites that have Captcha

我想制作一個多注冊表單,該表單可以在多個站點上發布,用戶不需要一遍又一遍地鍵入相同的數據,但是他會在此表單上發布。問題是某些站點可能有驗證碼,所以我需要一種方法使用cookie,會話,curl檢索表單上的驗證碼圖像,我不知道哪種方法可以幫助我。

在此處輸入圖片說明

這個問題變得很復雜,因為我需要存儲會話ID和cookie,因為如果我提交表單,其他站點應該知道那是請求驗證碼的同一用戶。 我用來獲取catpcha的php腳本是:

$ch = curl_init($url);//Site url
curl_setopt($ch, CURLOPT_COOKIEJAR, $file); //Save the cookie to a temporary file on the server
curl_setopt($ch, CURLOPT_COOKIEFILE, $file); 
curl_setopt($ch, CURLOPT_HEADER  ,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$content = curl_exec($ch);

preg_match("'<div class=\"captchaimage\">(.*?)<a class=\"captcha-refresh-link hide\"'si", $content, $matches ); // getting the captcha image

echo $matches[1]; //Displaying the image

第一次使用此代碼時,它顯示了損壞的圖像:

在此處輸入圖片說明

當我刷新頁面或在另一個標簽中打開時,我請求驗證碼的網站顯示了所需的驗證碼:

在此處輸入圖片說明

因此,我需要一些幫助,因為我在處理curl和cookie方面工作不多,但是我知道問題的解決方案如本網站https://www.betall.ie/register.html 我將不勝感激:)。

php代碼在這里: http : //codepad.viper-7.com/FMKrGR

curl_setopt($ch, CURLOPT_COOKIEJAR, $file);

您可以將不同的Cookie文件用於不同的$ url嗎? 我認為這可能會有所幫助。 來自不同URL的cookie項目不會混合。

找到了從另一個站點示例中獲取驗證碼的解決方案:

function getCaptcha($file){
   header ('Content-Type: image/png');
   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');
   curl_setopt($ch, CURLOPT_COOKIEJAR, $file);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_HEADER, 1);
   $out['result']  = curl_exec($ch);  //getting the html of the page 
   $out['error']   = curl_error($ch);
   $out['info']    = curl_getinfo($ch);
   curl_close($ch);  

   $matches = array();
   preg_match("'<div class=\"captchaimage\">(.*?)<a class=\"captcha-refresh-link hide\"'si", $out['result'], $matches );
   if(!isset($matches[1])){
      getCaptcha($file);
      return;
   }
   $img = $matches[1];
   $src = strpos($img, 'src="') + 5;
   $srcend = strpos($img, '"', $src);
   $img_src ='https://www.example.com' .  substr($img, $src, $srcend - $src);
   $img = substr($img, 0, $src)  . 'https://www.example.com' . substr($img, $src); //Getting the image captcha via regex

   $ch = curl_init($img_src);
   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_COOKIEFILE, $file);
   $out2['result'] = curl_exec($ch);
   $out2['error']  = curl_error($ch);
   $out2['info']   = curl_getinfo($ch);
   curl_close($ch); //requesting the image via curl

   return $out2['result']; //returning the image
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM