搜索
首页后端开发php教程PHP中CURL技术模拟登陆抓取网站信息,用与微信公众平台成绩查询_PHP教程

伴随微信的红火,微信公众平台成为许多开发者的下一个目标。笔者本身对于这种新鲜事物没有如此多的吸引力。但是最近有朋友帮忙开发微信公众平台中一个成绩查询的功能。于是便在空余时间研究了一番。

  主要的实现步骤是,通过PHP的CURL技术模拟登陆目标网站,通过登陆的用户,获取到用户的成绩信息,使用正则表达式对数据进行抓取和存储,使用HTML技术对数据进行重新弄排版。

  微信公众平台的功能就是通过浏览的目的来实现成绩查询。整体的技术实现就在于PHP的CURL技术。下面就随便找了一个文件,获取成绩。具体代码如下。

  


<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>


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


获取到成绩的界面

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/741659.htmlTechArticle伴随微信的红火,微信公众平台成为许多开发者的下一个目标。笔者本身对于这种新鲜事物没有如此多的吸引力。但是最近有朋友帮忙开发...
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
Vue.js与ASP.NET的结合,实现Web应用的性能优化和扩展的技巧和建议Vue.js与ASP.NET的结合,实现Web应用的性能优化和扩展的技巧和建议Jul 29, 2023 pm 05:19 PM

Vue.js与ASP.NET的结合,实现Web应用的性能优化和扩展的技巧和建议随着Web应用的快速发展,性能优化成为开发者不可或缺的重要任务。Vue.js作为一款流行的前端框架,与ASP.NET的结合可以帮助我们实现更好的性能优化和扩展。本文将会介绍一些技巧和建议,并提供一些代码示例。一、减少HTTP请求HTTP请求的数量直接影响着Web应用的加载速度。通过

ASP.NET程序中的MySQL连接池使用及优化技巧ASP.NET程序中的MySQL连接池使用及优化技巧Jun 30, 2023 pm 11:54 PM

如何在ASP.NET程序中正确使用和优化MySQL连接池?引言:MySQL是一种广泛使用的数据库管理系统,它具有高性能、可靠性和易用性的特点。在ASP.NET开发中,使用MySQL数据库进行数据存储是常见的需求。为了提高数据库连接的效率和性能,我们需要正确地使用和优化MySQL连接池。本文将介绍在ASP.NET程序中如何正确使用和优化MySQL连接池的方法。

生成式AI将在十个方面改变软件开发生成式AI将在十个方面改变软件开发Mar 11, 2024 pm 12:10 PM

译者|陈峻审校|重楼上个世纪90年代,当人们提起软件编程时,通常意味着选择一个编辑器,将代码检入CVS或SVN代码库,然后将代码编译成可执行文件。与之对应的Eclipse和VisualStudio等集成开发环境(IDE)可以将编程、开发、文档、构建、测试、部署等步骤纳入到一个完整的软件开发生命周期(SDLC)中,从而提高了开发人员的工作效率。近年来,流行的云计算和DevSecOps自动化工具提升了开发者的综合能力,使得更多的企业能够更加轻松地开发、部署和维护软件应用。如今,生成式AI作为下一代开

如何在ASP.NET程序中重连MySQL连接?如何在ASP.NET程序中重连MySQL连接?Jun 29, 2023 pm 02:21 PM

如何在ASP.NET程序中重连MySQL连接?在ASP.NET开发中,使用MySQL数据库是非常常见的。然而,由于网络或数据库服务器的原因,有时会导致数据库连接中断或超时。在这种情况下,为了保证程序的稳定性和可靠性,我们需要在连接断开后重新建立连接。本文将介绍如何在ASP.NET程序中实现重连MySQL连接的方法。引用必要的命名空间首先,在代码文件的头部引用

Vue.js与ASP.NET的结合,实现企业级应用的开发和部署Vue.js与ASP.NET的结合,实现企业级应用的开发和部署Jul 29, 2023 pm 02:37 PM

Vue.js与ASP.NET的结合,实现企业级应用的开发和部署在当今快速发展的互联网技术领域,企业级应用的开发和部署变得越来越重要。Vue.js和ASP.NET是两个在前端和后端开发中广泛使用的技术,将它们结合起来可以为企业级应用的开发和部署带来诸多优势。本文将通过代码示例介绍如何使用Vue.js和ASP.NET进行企业级应用的开发和部署。首先,我们需要安装

如何在ASP.NET程序中正确配置和使用MySQL连接池?如何在ASP.NET程序中正确配置和使用MySQL连接池?Jun 29, 2023 pm 12:56 PM

如何在ASP.NET程序中正确配置和使用MySQL连接池?随着互联网的发展和数据量的增大,对数据库的访问和连接需求也在不断增加。为了提高数据库的性能和稳定性,连接池成为了一个必不可少的技术。本文主要介绍如何在ASP.NET程序中正确配置和使用MySQL连接池,以提高数据库的效率和响应速度。一、连接池的概念和作用连接池是一种重复使用数据库连接的技术,在程序初始

aspnet有哪些内置对象aspnet有哪些内置对象Nov 21, 2023 pm 02:59 PM

ASP.NET中的内置对象有“Request”、“Response”、“Session”、“Server”、“Application”、 “HttpContext”、“Cache”、“Trace”、“Cookie”和“Server.MapPath”:1、Request,表示客户端发出的HTTP请求;2、Response:表示Web服务器返回给客户端的HTTP响应等等。

在Linux上使用Visual Studio进行ASP.NET开发的推荐配置在Linux上使用Visual Studio进行ASP.NET开发的推荐配置Jul 06, 2023 pm 08:45 PM

在Linux上使用VisualStudio进行ASP.NET开发的推荐配置概述:随着开源软件的发展和Linux操作系统的普及,越来越多的开发者开始在Linux上进行ASP.NET开发。而作为一款功能强大的开发工具,VisualStudio在Windows平台上一直占据着主导地位。本文将介绍如何在Linux上配置VisualStudio来进行ASP.NE

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前By尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
1 个月前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器