CURL technology in PHP simulates login and captures website information, and uses it to query results on WeChat public platform_PHP tutorial

WBOY
Release: 2016-07-13 10:36:07
Original
1228 people have browsed it

With the popularity of WeChat, the WeChat public platform has become the next target for many developers. The author himself is not so attracted to this new thing. But recently, a friend helped develop a score query function on the WeChat public platform. So I did some research in my spare time.

The main implementation steps are to simulate logging into the target website through PHP's CURL technology, obtain the user's performance information through the logged-in user, use regular expressions to capture and store the data, and use HTML technology to reconstruct the data. Do the typesetting.

The function of the WeChat public platform is to query scores through browsing. The overall technical implementation lies in PHP's CURL technology. Let’s just find a file and get the results. The specific code is as follows.

 


<span <</span><span HTML</span><span ></span>
<span <</span><span HEAD</span><span ><</span><span TITLE</span><span ></span>请您登录<span </</span><span TITLE</span><span ></span>
<span <</span><span script </span><span language</span><span ="JavaScript"</span><span ></span>
<span function</span><span  Judge()
    {
    </span><span var</span><span  WebUserNO</span><span =</span><span document.all[</span><span "</span><span WebUserNO</span><span "</span><span ].value;
    </span><span if</span><span (WebUserNO</span><span ==</span><span ""</span><span )
       {alert(</span><span "</span><span 登录用户不能为空!</span><span "</span><span );
       document.all[</span><span "</span><span WebUserNO</span><span "</span><span ] .focus();
       </span><span return</span> <span false</span><span ;
       }
    
}
</span><span </</span><span script</span><span ></span>
<span <</span><span META </span><span http-equiv</span><span =Content-Type </span><span content</span><span ="text/html; charset=gb2312"</span><span ></span>
<span <</span><span STYLE </span><span type</span><span =text/css</span><span ></span><span TD </span><span {</span><span 
    FONT-SIZE</span><span :</span><span  12px
</span><span }</span><span 
p1 </span><span {</span><span 
    FONT-SIZE</span><span :</span><span  12px
</span><span }</span><span 
INPUT </span><span {</span><span 
    FONT-SIZE</span><span :</span><span  12px
</span><span }</span><span 
p2 </span><span {</span><span 
    FONT-SIZE</span><span :</span><span  12px</span><span ;</span><span  LINE-HEIGHT</span><span :</span><span  14pt
</span><span }</span><span 
p3 </span><span {</span><span 
    FONT-SIZE</span><span :</span><span  14px
</span><span }</span><span 
p4 </span><span {</span><span 
    FONT-SIZE</span><span :</span><span  14px</span><span ;</span><span  LINE-HEIGHT</span><span :</span><span  14pt
</span><span }</span><span 
p5 </span><span {</span><span 
    FONT-SIZE</span><span :</span><span  16px
</span><span }</span><span 
p6 </span><span {</span><span 
    FONT-SIZE</span><span :</span><span  14px</span><span ;</span><span  LINE-HEIGHT</span><span :</span><span  180%
</span><span }</span><span 
p7 </span><span {</span><span 
    FONT-SIZE</span><span :</span><span  12px</span><span ;</span><span  COLOR</span><span :</span><span  #136792</span><span ;</span><span  LINE-HEIGHT</span><span :</span><span  160%
</span><span }</span><span 
BIG </span><span {</span><span 
    FONT-SIZE</span><span :</span><span  18px
</span><span }</span><span 
A:link </span><span {</span><span 
    COLOR</span><span :</span><span  #0000ff
</span><span }</span><span 
A:visited </span><span {</span><span 
    COLOR</span><span :</span><span  #0000ff
</span><span }</span><span 
A:hover </span><span {</span><span 
    COLOR</span><span :</span><span  #ff0000
</span><span }</span><span 
hand </span><span {</span><span 
    CURSOR</span><span :</span><span  hand</span><span ;</span><span  BACKGROUND-COLOR</span><span :</span><span  rgb(208,207,192)
</span><span }</span>
<span </</span><span STYLE</span><span ></span>
<span <!--</span><span style end</span><span --></span>
<span <</span><span META </span><span content</span><span ="MSHTML 6.00.2600.0"</span><span  name</span><span =GENERATOR</span><span ></</span><span HEAD</span><span ></span>
<span <</span><span BODY </span><span bgColor</span><span =#ffffff </span><span topMargin</span><span =7 </span><span marginheight</span><span ="0"</span><span  marginwidth</span><span ="25"</span><span ></span>
<span <</span><span form </span><span name</span><span ="LoginForm"</span><span  method</span><span ="post"</span><span  action</span><span ="qing.php"</span><span ></span>
<span <</span><span TABLE </span><span cellSpacing</span><span =0 </span><span cellPadding</span><span =0 </span><span width</span><span ="100%"</span><span  border</span><span =0</span><span ></span>
  <span <</span><span TBODY</span><span ></span>
  <span <</span><span TR</span><span ></span>
    <span <</span><span TD </span><span bgColor</span><span =#e6e6e6 </span><span height</span><span =20</span><span ></</span><span TD</span><span ></span>
      <span <</span><span TD </span><span align</span><span =right </span><span bgColor</span><span =#e6e6e6</span><span ></span><span  </span><span </</span><span TD</span><span ></span>
    <span </</span><span TR</span><span ></</span><span TBODY</span><span ></</span><span TABLE</span><span ><</span><span BR</span><span ></span>
<span <</span><span TABLE </span><span cellSpacing</span><span =0 </span><span cellPadding</span><span =1 </span><span width</span><span =492 </span><span align</span><span =center </span><span border</span><span =0</span><span ></span>
  <span <</span><span TBODY</span><span ></span>
  <span <</span><span TR</span><span ></span>
    <span <</span><span TD</span><span ></span>
      <span <</span><span TABLE </span><span borderColor</span><span =#c1eaff </span><span cellSpacing</span><span =0 </span><span cellPadding</span><span =20 </span><span width</span><span =474 
      </span><span align</span><span =center </span><span border</span><span =1</span><span ></span>
        <span <</span><span TBODY</span><span ></span>
        <span <</span><span TR</span><span ></span>
          <span <</span><span TD</span><span ><</span><span TABLE </span><span width</span><span =283 </span><span height</span><span ="100"</span><span  
              border</span><span =0 </span><span align</span><span =center </span><span cellPadding</span><span =0 </span><span cellSpacing</span><span =0</span><span ></span>
                                   <span <</span><span tr</span><span ></span>
                      <span <</span><span td </span><span width</span><span ="50"</span><span  rowspan</span><span ="4"</span><span ></span><span  </span><span </</span><span td</span><span ></span>
                    <span <</span><span td </span><span align</span><span ="left"</span><span ></span>
                      <span </</span><span td</span><span ></span>
                      <span </</span><span tr</span><span ></span>
                                   <span <</span><span tr</span><span ></span>
                                     <span <</span><span td </span><span height</span><span ="22"</span><span  align</span><span ="left"</span><span ></span><span 用户名:
                                     </span><span <</span><span input </span><span name</span><span ="WebUserNO"</span><span  type</span><span ="text"</span><span  id</span><span ="WebUserNO"</span><span  size</span><span ="12"</span><span ></</span><span td</span><span ></span>
                                   <span </</span><span tr</span><span ></span>
                                   <span <</span><span tr</span><span ></span>
                                     <span <</span><span td </span><span height</span><span ="22"</span><span  align</span><span ="left"</span><span ></span>密<span   </span><span 码:
                                     </span><span <</span><span input </span><span name</span><span ="Password"</span><span  type</span><span ="password"</span><span  id</span><span ="Password"</span><span  size</span><span ="12"</span><span ></</span><span td</span><span ></span>
                                   <span </</span><span tr</span><span ></span>
                                   <span <</span><span tr</span><span ></span>
                                     <span <</span><span td </span><span height</span><span ="22"</span><span  align</span><span ="left"</span><span  valign</span><span ="middle"</span><span ><</span><span p</span><span ></span><span 附加码:
                                     </span><span <</span><span input </span><span name</span><span ="Agnomen"</span><span  type</span><span ="text"</span><span  id</span><span ="Agnomen"</span><span  size</span><span ="12"</span><span ></span>
                                     <span </</span><span p</span><span ></span>
                                     <span <</span><span p</span><span ><</span><span A </span><span href</span><span ="User_JSP/FuJiaMa.htm"</span><span  target</span><span ="_blank"</span> <span ><</span><span img </span><span src</span><span ="http://218.61.108.163/ACTIONVALIDATERANDOMPICTURE.APPPROCESS"</span><span  width</span><span ="60"</span><span  height</span><span ="20"</span><span  alt</span><span ="验证码说明"</span><span  border</span><span ="0"</span><span ></</span><span a</span><span ></</span><span p</span><span ></</span><span td</span><span ></span>
                                   <span </</span><span tr</span><span ></span>
                  <span <</span><span tr </span><span align</span><span ="center"</span><span ></span> 
                    <span <</span><span td </span><span colspan</span><span ="2"</span><span ><</span><span input </span><span type</span><span ="image"</span><span  border</span><span ="0"</span><span  name</span><span ="submit"</span><span  src</span><span ="http://218.61.108.163/User_JSP/images/Logon.gif"</span><span  width</span><span ="37"</span><span  height</span><span ="18"</span><span  onClick</span><span ="javascript:return Judge();"</span><span ></span>
                    
                    <span </</span><span td</span><span ></span>
                <span </</span><span tr</span><span ></span>    
                  <span <</span><span tr</span><span ></span> 
                    <span <</span><span td </span><span colspan</span><span ="2"</span><span ><</span><span div </span><span align</span><span ="center"</span><span ><</span><span input </span><span name</span><span ="applicant"</span><span  type</span><span ="hidden"</span><span  value</span><span ="ACTIONQUERYSTUDENTSCORE"</span><span ></</span><span div</span><span ></</span><span td</span><span ></span>
                <span </</span><span tr</span><span ></span>    
                <span </</span><span TABLE</span><span ></span>
            <span <</span><span br</span><span ></span>
          <span </</span><span TD</span><span ></span>
        <span </</span><span TR</span><span ></span>
        <span </</span><span TABLE</span><span ></</span><span TD</span><span ></</span><span TR</span><span ></</span><span TBODY</span><span ></</span><span TABLE</span><span ></span>
<span </</span><span form</span><span ></span>        
<span <</span><span BR</span><span ></span>
<span <</span><span BR</span><span ></span>
<span </</span><span BODY</span><span ></</span><span HTML</span><span ></span>
Copy after login


qing.php

<?<span php
    </span><span $cookie_file</span> = <span tempnam</span>('./temp','cookie'<span );
    </span><span $login_url</span> = 'http://218.61.108.163/ACTIONQUERYSTUDENTSCORE.APPPROCESS'<span ;
    
    </span><span $post_fields</span> = 'WebUserNO=stuid&Password=passwd&Agnomen=code&applicant=ACTIONQUERYGRADUATESCHOOLREPORTBYSELF'<span ;
    
    </span><span $ch</span> = curl_init(<span $login_url</span><span );
    curl_setopt(</span><span $ch</span>, CURLOPT_HEADER, 0<span );
    curl_setopt(</span><span $ch</span>, CURLOPT_RETURNTRANSFER, 1<span );
    curl_setopt(</span><span $ch</span>, CURLOPT_POST, 1<span );
    curl_setopt(</span><span $ch</span>, CURLOPT_COOKIEJAR, <span $cookie_file</span><span );
    curl_setopt(</span><span $ch</span>, CURLOPT_POSTFIELDS, <span $post_fields</span><span );
    curl_exec(</span><span $ch</span><span );
    curl_close(</span><span $ch</span><span );
    
    </span><span $url</span>='http://218.61.108.163/ACTIONQUERYGRADUATESCHOOLREPORTBYSELF.APPPROCESS'<span ;
    </span><span $ch</span> = curl_init(<span $url</span><span );
    curl_setopt(</span><span $ch</span>, CURLOPT_HEADER, 0<span );
    curl_setopt(</span><span $ch</span>, CURLOPT_RETURNTRANSFER, 0<span );
    curl_setopt(</span><span $ch</span>, CURLOPT_COOKIEFILE, <span $cookie_file</span><span );
    </span><span $contents</span> = curl_exec(<span $ch</span><span );
    
    </span><span //</span><span 正则表达式提取数据。</span>
    <span $match</span>="|(<=<td>).*(?=</td>)|"<span ;
    </span><span preg_match_all</span>(<span $match</span>,<span $contents</span>,<span $b</span><span );
    </span><span $abc</span> = <span $b</span>[0<span ];
    </span><span $abs</span> = <span $b</span>[1<span ];
    </span><span $abd</span> = <span $b</span>[1<span ];
    </span><span echo</span> <span $abc</span><span ;
    </span><span echo</span> <span $abs</span><span ;
    </span><span echo</span> <span $abd</span><span ;
    curl_close(</span><span $ch</span><span );
</span>?>
Copy after login


Interface for obtaining results

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/741659.htmlTechArticleWith the popularity of WeChat, the WeChat public platform has become the next target for many developers. The author himself is not so attracted to this new thing. But recently a friend helped me develop...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!