2014-02-21 53 views
2

因此,bascially是新的php。我想從網站上獲得catpcha。然後我想在我的網頁上展示併發送一個小的發佈請求並獲得結果。我在說的網站是http://www.bollywoodmotion.com/mobile-tracker-with-name.html使用Curl獲取驗證碼併發送數據並抓取結果

我想從該頁面獲取驗證碼到我的頁面,並在我的頁面中輸入驗證碼,並從我的頁面發送驗證碼。我在一個使用c#的軟件中完成了這項工作。我也想要一個Web版本,因爲我不知道在PHP。任何方式,我試圖尋找和捲曲是我的最佳選擇。所以有人可以幫助我的示例PHP代碼。

這個請求由它來做。

http://www.bollywoodmotion.com/mobile-tracker-process.html

POST /mobile-tracker-process.html HTTP/1.1 
Host: www.bollywoodmotion.com 
User-Agent: Mozilla/5.0 (Windows NT 6.2; rv:26.0) Gecko/20100101 Firefox/26.0 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-US,en;q=0.5 
Accept-Encoding: gzip, deflate 
Referer: http://www.bollywoodmotion.com/mobile-tracker-with-name.html 
Cookie: __utma=164959532.607980600.1392265746.1392293744.1392969352.5; __utmz=164959532.1392265754.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); 
PHPSESSID=t37p2pqeclbmc2tfvd8tt18qs5; __utmb=164959532.2.9.1392969356013; __utmc=164959532 
Connection: keep-alive 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 36 

num=960xxxxxx&6_letters_code=hy5xjf 
HTTP/1.1 200 OK 
Date: Fri, 21 Feb 2014 07:56:11 GMT 
Server: Apache 
Expires: Thu, 19 Nov 1981 08:52:00 GMT 
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
Pragma: no-cache 
Content-Encoding: gzip 
Set-Cookie: dle_user_id=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.bollywoodmotion.com; httponly 
Set-Cookie: dle_password=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.bollywoodmotion.com; httponly 
Set-Cookie: dle_hash=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.bollywoodmotion.com; httponly 
Last-Modified: Mon, 16 Sep 2013 23:55:25 GMT 
Keep-Alive: timeout=10, max=30 
Connection: Keep-Alive 
Transfer-Encoding: chunked 
Content-Type: text/html 
+0

您是否試圖自動化發送短信的過程?如果是這樣,那麼寶萊塢運動的業主是否知道您將使用他們的腳本服務? –

+0

我沒有觸及短信部分。我上面發佈的鏈接是一個反向電話號碼查找就像真正的來電者,但只爲印度用戶工作。我試圖聯繫他們,但他們從來沒有回答。我知道​​有一些API正在使用來抓取結果,但它以某種方式隱藏或沒有人知道它。 –

回答

8

這是對我的問題了,我沒有得到answer.However,我有了答案now.This是你想要的完美的例子。我使用網站中包含的網頁源代碼中的驗證碼網址檢索驗證碼。在()之間使用captcha-url提取圖像。然後保持會話並再次發送請求。部分是你必須將數據提交給表單的URL,而不是頁面。

<?php 

    $cookie="cookie.txt"; 

    function open($url) 
    { 
     $ch = curl_init(); 

     curl_setopt($ch, CURLOPT_URL,$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_HEADER, 0); 
     curl_setopt($ch, CURLOPT_COOKIE, 1); 
     curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie); 
     curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
     curl_setopt ($ch, CURLOPT_REFERER, $url); 
     $result = curl_exec($ch); 
     curl_close($ch); 

     return $result; 
    } 

    function between($string, $start, $end) 
    { 
     $out = explode($start, $string); 

     if(isset($out[1])) 
     { 
      $string = explode($end, $out[1]); 
      echo $string[0]; 
      return $string[0]; 
     } 

     return ''; 
    } 

    function get_captcha() 
    { 
     $url = 'https://academics.vit.ac.in/student/stud_login.asp'; 
     $open = open($url); 
     $code = between($open, '<img src='https://academics.vit.ac.in/student/captcha.asp', '">'); 
     return 'https://academics.vit.ac.in/student/captcha.asp' . $code; 

    } 

    function rahul() 
    { 
     $capth=htmlspecialchars($_POST['code']); 

     echo $capth; 

     $username="xyz"; 
     $password="abc"; 
     $url=url of the form in which you want to submit your data; 
     $cookie="cookie.txt"; 
     $veri=$capth; 

     $com="Login"; 

     $postdata = "regno=".$username."&passwd=".$password."&vrfcd=".$veri."&submit=".$com; 

     $ch = curl_init(); 
     curl_setopt ($ch, CURLOPT_URL, $url); 
     curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
     curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
     curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
     curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
     curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie); // <-- add this line 
     curl_setopt ($ch, CURLOPT_REFERER, $url); 

     curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
     curl_setopt ($ch, CURLOPT_POST, 1); 
     $result = curl_exec ($ch); 

     echo $result; 

     $data = curl_exec($ch); 
    } 
?> 

<html> 
    <body> 
     <form action="" method="post"> 
      <img src="<?php echo get_captcha(); ?>" border="0" /><br /> 
      <input type="text" name="code" value="<?= isset($_POST['code']) ? htmlspecialchars($_POST['code']) : '' ?>" /><br /> 
      <input type="submit" name="submit" value="submit"/> 
     </form> 

     <?php 
      if(isset($_POST['submit'])) { 
       rahul(); 
      } 
     ?> 
    </body> 
</html> 
+0

適合我。 – Diffy