使用snoopy类实现模拟登陆

news/2024/7/4 0:49:00 标签: class, 浏览器, 域名
class="baidu_pl">
class="article_content clearfix">
class="markdown_views prism-atom-one-light">

1.在网上下载一个Snoopy.class.php的文件

2.代码实现:

class="prettyprint">class=" hljs xml">class="php">class="hljs-preprocessor"><?php

set_time_limit(class="hljs-number">0);

class="hljs-keyword">require class="hljs-string">"Snoopy.class.php";

class="hljs-variable">$snoopy=class="hljs-keyword">new Snoopy();

class="hljs-variable">$snoopy->referer=class="hljs-string">'你要模拟登陆的域名';class="hljs-comment">//例如:http://www.baidu.com/

class="hljs-variable">$snoopy->agent=class="hljs-string">"定义浏览器根";

class="hljs-variable">$post[class="hljs-string">'username'] =class="hljs-string">'登陆账号';class="hljs-comment">//根据你要模拟登陆的网站具体的传值 名称来定

class="hljs-variable">$post[class="hljs-string">'password'] =class="hljs-string">'登陆密码';class="hljs-comment">//根据你要模拟登陆的网站具体的传值 名称来定

class="hljs-variable">$url=class="hljs-string">'你要模拟登陆的域名,数据提交地址';class="hljs-comment">//登陆数据提交的URL地址

class="hljs-variable">$snoopy->submit(class="hljs-variable">$url,class="hljs-variable">$post);

class="hljs-variable">$snoopy->fetch(class="hljs-string">"你要模拟登陆的域名");class="hljs-comment">//希望获取的页面数据

class="hljs-keyword">echo class="hljs-variable">$snoopy->results;class="hljs-comment">//输出结果,登陆成功

第二种:使用curl函数模拟登陆

1.代码实现:储存COOKIE

class="prettyprint">class=" hljs xml">class="php">class="hljs-preprocessor"><?php

set_time_limit(class="hljs-number">0);

class="hljs-variable">$cookie_file=tempnam(class="hljs-string">'./tmp',class="hljs-string">'cookie');class="hljs-comment">//tmp目录首先创建好,设置COOKIE文件

class="hljs-variable">$curl=curl_init();

class="hljs-variable">$login_url=class="hljs-string">'你要模拟登陆的域名,数据提交地址';

class="hljs-variable">$curlPost=class="hljs-string">"usename=登陆账号&password=登陆密码";class="hljs-comment">//根据你要模拟登陆的网站具体的传值 名称来定

curl_setopt(class="hljs-variable">$ch,CURLOPT_URL,class="hljs-variable">$login_url);

class="hljs-comment">//启用时会将头文件的信息作为数据流输出

curl_setopt(class="hljs-variable">$curl,CURLOPT_HEADER,class="hljs-number">0); class="hljs-comment">//设定是否输出页面内容

curl_setopt(class="hljs-variable">$curl,CURLOPT_RETURNTRANSFER,class="hljs-number">1);

curl_setopt(class="hljs-variable">$curl,CURLOPT_POST,class="hljs-number">1); class="hljs-comment">//设置请求发送方式,post或get,CURLOPT_POST或CURLOPT_GET

curl_setopt(class="hljs-variable">$curl,CURLOPT_POSTFIELDS,class="hljs-variable">$curlPost);

curl_setopt(class="hljs-variable">$curl,CURLOPT_COOKIEJAR,class="hljs-variable">$cookie_file); class="hljs-comment">//保存cookie

curl_exec(class="hljs-variable">$curl);class="hljs-comment">//执行

curl_close(class="hljs-variable">$curl);class="hljs-comment">//关闭

class="hljs-comment">//2.实现模拟登陆

class="hljs-variable">$curl=curl_init();

class="hljs-variable">$login_url2=class="hljs-string">"你要模拟登陆的域名";

curl_setopt(class="hljs-variable">$curl,CURLOPT_URL,class="hljs-variable">$login_url2);class="hljs-comment">//提交登陆的url

curl_setopt(class="hljs-variable">$curl,CURLOPT_HEADER,class="hljs-number">0); 

curl_setopt(class="hljs-variable">$curl,CURLOPT_RETURNTRANSFER,class="hljs-number">0);

curl_setopt(class="hljs-variable">$curl,CURLOPT_COOKIEFILE,class="hljs-variable">$cookie_file); class="hljs-comment">//读取cookie

curl_exec(class="hljs-variable">$curl);class="hljs-comment">//执行

curl_close(class="hljs-variable">$curl);class="hljs-comment">//关闭

http://www.niftyadmin.cn/n/1813919.html

相关文章

yii2.0 验证码功能的实现

首先知晓我们在使用验证码的时候通常是和我们的表单小部件配合使用 首先我们创建model层 新建一个php文件 名字叫做Verifycode.php 要在我们的model层 创建我们的验证码的验证规则&#xff0c;我这里简单的写两个规则 一个是 非空 另一个是验证码必须验证正确 规则写在我们…

asp.net自动生成页面头部信息

<% Page Language"C#" Inherits"BasePage"%><!DOCTYPE html><html><head runat"server"><title>管理首页</title></head><body></body></html> 我们通过asp.net在其生存周期内对其…

guge

http://www.google.com.hk/转载于:https://www.cnblogs.com/mingyongcheng/archive/2012/03/24/2415953.html

yii2.0 rbac权限控制

要想使用yii rbac组件 首先需要在我们的配置文件中开启 rbac组件 在common/config/main-local.php 中添加 下边的组建 authManager > [class > yii\rbac\DbManager,itemTable > auth_item,assignmentTable > auth_assignment,itemChildTable > auth_item_chi…

sizeof 关键字!

括号分情况是可以省略的&#xff0c;所以它不是函数&#xff01; sizeof在计算变量 所占空间大小时&#xff0c;括号可以省略 在计算类型大小时&#xff0c;括号不能省略 转载于:https://www.cnblogs.com/ai616818/archive/2012/03/26/2418312.html

yii2.0实现文件上传

本文档教授大家在yii2.0里实现文件上传 首先我们来实现单文件上传 第一步 首先建立一个关于上传的model层 如果你有已经建好的可以使用表单小部件的model层 也可以直接用这个。在这里我们新建一个新的model层 在model层新建文件 Upload.php <?phpnamespace frontend\mod…

DP(hdu1058)

状态转移方程&#xff1a;f[i]min(f[x]*2f[y]*3f[p]*5f[q]*7);这题如果不打表超时&#xff0c;不懂为啥&#xff1f; #include<iostream>using namespace std;int f[6000];int min(int a,int b,int c,int d,int *q){if(a<b&&a<c&&a<d) { …

lucene.Net学习一

建索引的代码&#xff0c;代码里面有注释 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using Lucene.Net.Index;using Lucene.Net.Store;using Lucene.Net.Util;using Lucene.Net.Analysis.Standard;using Lucene.Net…