糖果派对官方网站_可以赌钱的糖果游戏_手机版
C# 模拟网址登录

C# 模拟网址登录

作者:网络编程    来源:未知    发布时间:2019-12-24 20:50    浏览量:

那方面包车型大巴生手,想试一下用VC做叁个设想登入这几个网址的小程序练练手.在网络看了有的连锁学科,然后用fiddler4抓包看看,可是那几个网址比较复杂,用的是Get方法和HTTPs左券,在这里个网址的登入界面输入账号密码后抓包,一下得到4个动作,麻烦大腕解析该怎么入手写那么些顺序

数据库操作程序(db)

db中含有五个java文件,MyDataSource,MYSQLControl。那多个公文的功效已在前面表达了。

package db;

import javax.sql.DataSource;
import org.apache.commons.dbcp2.BasicDataSource;
/**
 * @author:合肥工业大学 管理学院 钱洋
 * @email:1563178220@qq.com
 */
public class MyDataSource {

    public static DataSource getDataSource(String connectURI){

        BasicDataSource ds = new BasicDataSource();
         //MySQL的jdbc驱动
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUsername("root");              //所要连接的数据库名
        ds.setPassword("112233");                //MySQL的登陆密码
        ds.setUrl(connectURI);

        return ds;

    }

}

C# 模拟网址登录。这里本人写了过多的操作方面,本程序里面用到多少个格局MYSQLControl.getListInfoBySQL(卡塔尔及MYSQLControl.executeUpdatecontainId(卡塔尔国。别的措施,大家能够忽视不看,仅供大家写其余程序的时候仿照效法。

package db;
import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ColumnListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import model.ContentModel;
import model.DouBanUserUrl;

/**
 * @author:合肥工业大学 管理学院 钱洋
 * @email:1563178220@qq.com
 */
public class MYSQLControl {
    static final Log logger = LogFactory.getLog(MYSQLControl.class);
    static DataSource ds = MyDataSource.getDataSource("jdbc:mysql://127.0.0.1:3306/moviedata");
    static QueryRunner qr = new QueryRunner(ds);
    //第一类方法
    public static void executeUpdate(String sql){
      try {
        qr.update(sql);
      } catch (SQLException e) {
          logger.error(e);
      }
    }

    //按照SQL查询单个结果
        public static Object getScalaBySQL ( String sql ){

            ResultSetHandler<Object> h = new ScalarHandler<Object>(1);
            Object obj = null;
            try {
                obj = qr.query(sql, h);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return obj;

        }
        //按照SQL查询多个结果
        public static <T> List<T> getListInfoBySQL (String sql, Class<T> type ){
            List<T> list = null;
            try {
                list = qr.query(sql,new BeanListHandler<T>(type));
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return list;
        }
        //查询一列
        public static List<Object> getListOneBySQL (String sql,String id){
            List<Object> list=null;

            try {
                list = (List<Object>) qr.query(sql, new ColumnListHandler(id));
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return list;
        }
    //第二类数据库操作方法
    public static void executeUpdate(List<DouBanUserUrl> data) throws SQLException {

        Object[][] params = new Object[data.size()][2];
        for ( int i=0; i<params.length; i++ ){
            params[i][0] = data.get(i).getUser_id();
            params[i][1] = data.get(i).getUser_contactsid();

        }
        try{
            qr.batch("insert into doubancontacts (user_id, user_contactsid)"
                    + "values (?,?)", params);

//          qr.update("update movie set is_crawler=1 where id='"+id+"'");
        }catch( Exception e){
            logger.error(e);
        }

    }
    //第三类数据库操作方法
    public static void executeUpdatecontainId(List<DouBanUserUrl> data,String id) throws SQLException {

        Object[][] params = new Object[data.size()][2];
        for ( int i=0; i<params.length; i++ ){
            params[i][0] = data.get(i).getUser_id();
            params[i][1] = data.get(i).getUser_contactsid();

        }
        try{
            qr.batch("insert into doubancontacts (user_id, user_contactsid)"
                    + "values (?,?)", params);

            qr.update("update doubancontacts set tag=1 where user_contactsid='"+id+"'");
        }catch( Exception e){
            logger.error(e);
        }

    }
    public void handleTable ( ){
        int rowNum =  Integer.valueOf(getScalaBySQL("SELECT count(*) FROM qirui_jianghuai2016data.forum_comment;").toString() );
        System.out.println(rowNum);
        if ( rowNum >= 5000000 ){
            int tableNum = Integer.valueOf(getScalaBySQL("SELECT number_flag FROM qirui_jianghuai2016data.table_utils_comment;").toString() );
            executeUpdate("rename table qirui_jianghuai2016data.forum_comment to qirui_jianghuai2016data.forum_comment"+(tableNum+1));
            executeUpdate("update qirui_jianghuai2016data.table_utils_comment set number_flag="+(tableNum+1));
            executeUpdate("CREATE TABLE `qirui_jianghuai2016data`.`forum_comment` ( `comm_id` varchar(50) NOT NULL DEFAULT '' COMMENT '评论id,命名规则论坛编号+帖子id+评论ID',`post_id` varchar(50) DEFAULT NULL COMMENT '帖子ID,命名规则为论坛编号+帖子对应ID',`addr_id` varchar(50) DEFAULT NULL,`comm_userid` varchar(50) DEFAULT NULL COMMENT '发帖作者ID,命名规则论坛编号+作者id',`comm_userurl` varchar(100) DEFAULT NULL COMMENT '用户的url',`comm_time` datetime DEFAULT NULL COMMENT '用户的评论时间',`comm_content` text COMMENT '用户的评论内容',`craw_time` datetime DEFAULT NULL COMMENT '爬取时间',`report_time` datetime DEFAULT NULL COMMENT '数据更新时间',PRIMARY KEY (`comm_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
        } 
    }
    //操作评论的数据库
    public static void executeUpdateContent(List<ContentModel> data,String user_contactsid) throws SQLException {

        Object[][] params = new Object[data.size()][8];
        for ( int i=0; i<params.length; i++ ){
            params[i][0] = data.get(i).getUser_id();
            params[i][1] = data.get(i).getMovie_name();
            params[i][2] = data.get(i).getMovie_id() ;
            params[i][3] = data.get(i).getIntroduce();
            params[i][4] = data.get(i).getRating();
            params[i][5] = data.get(i).getRating_time() ;
            params[i][6] = data.get(i).getComment();
            params[i][7] = data.get(i).getTags() ;
        }
        try{
            qr.batch("insert into doubanusercontent (user_id, movie_name,movie_id, introduce,rating,rating_time,comment,tags)"
                    + "values (?,?,?,?,?,?,?,?)", params);
            qr.update("update doubanuserid set tag=1 where user_contactsid='"+user_contactsid+"'");
        }catch( Exception e){
            logger.error(e);
        }

    }
}

每回诉求与下三回号令之间的关联便是历次央求后归来的Cookies数据,前壹遍的回到Cookie数据需求同下一遍号召一齐发送到服务器,那也是C#模仿网址登入的第大器晚成。详见以下逻辑代码:

bb电子糖果派对 1

鸡犬不留验证码的思绪

诚如化解验证码难点的思路是:将网址验证码对应的图片下载下来,以手工业输入的格局,实行登入。登录完结后,便得以给一个url或多少个url,爬取该url对应的html或json数据对应的新闻。注意在爬取多个url的时候,只供给三回登入就可以,这样制止了多次输入验证码图片

正如,以豆瓣为例,实行登入,并拿走唯有登录之后,技巧看出的音信

package simulate;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;
import util.HTTPUtils;
/**
 * @author:合肥工业大学 管理学院 钱洋
 * @email:1563178220@qq.com
 * @ 
 */
public class DoubanSimulate {
    private static HttpClient httpClient=new DefaultHttpClient();

    //主登录入口
    public static void loginDouban(){
//      String redir="https://www.douban.com/people/144537495/";
        String login_src="https://accounts.douban.com/login";
        //输入用户名及密码
        String form_email="";
        String form_password="";
        //获取验证码
        String captcha_id=getImgID();
        String login="登录";
        String captcha_solution="";
        //输入验证码
        System.out.println("请输入验证码:");
        BufferedReader buff=new BufferedReader(new InputStreamReader(System.in));
        try {
            captcha_solution=buff.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }

        //构建参数,即模拟需要输入的参数。这部分通过抓包获得。不会抓包的请看我之前写的一些博客
        List<NameValuePair> list=new ArrayList<NameValuePair>();
        list.add(new BasicNameValuePair("form_email", form_email));
        list.add(new BasicNameValuePair("form_password", form_password));
        list.add(new BasicNameValuePair("captcha-solution", captcha_solution));
        list.add(new BasicNameValuePair("captcha-id", captcha_id));
        list.add(new BasicNameValuePair("login", login));
        HttpPost httpPost = new HttpPost(login_src);
        try {
            //向后台请求数据,登陆网站
            httpPost.setEntity(new UrlEncodedFormEntity(list));
            HttpResponse response=httpClient.execute(httpPost);
            HttpEntity entity=response.getEntity();
            String result=EntityUtils.toString(entity,"utf-8");
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    /**
     * 获取验证码图片“token”值
     * @return token
     */
    private static String getImgID(){
        //Json的地址[数据中包含验证码的地址]
        String src="https://www.douban.com/j/misc/captcha";
        HttpGet httpGet=new HttpGet(src);
        String token="";
        try {
            HttpResponse response=httpClient.execute(httpGet);
            HttpEntity entity=response.getEntity();
            //将json数据转化为map,对应的是key,value的形式。不理解json数据的,请看我前面的关于json解析的博客
            String content=EntityUtils.toString(entity,"utf-8");
            Map<String,String> mapList=getResultList(content);
            token=mapList.get("token");
            //获取验证码的地址
            String url="https:"+mapList.get("url");
            //下载验证码并存储到本地
            downImg(url);
            //System.out.println(token);
            //System.out.println(url);
            //System.out.println(content);
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return token;
    }
    /**
     * 用JSON 把数据格式化,并生成迭代器,放入Map中返回
     * @param content 请求验证码时服务器返回的数据
     * @return Map集合
     */
    public static Map<String,String> getResultList(String content){
        Map<String,String> maplist=new HashMap<String,String>();
        try {
            JSONObject jo=new JSONObject(content.replaceAll(",\"r\":false", ""));
            Iterator it = jo.keys();
            String key="";
            String value="";
            while(it.hasNext()){
                key=(String) it.next();
                value=jo.getString(key);
                maplist.put(key, value);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return maplist;
    }
    /**
     * 此方法是下载验证码图片到本地
     * @param src  给个验证图片完整的地址
     * @throws IOException 
     */
    private static void downImg(String src) throws IOException{
        File fileDir=new File("E:\钱洋个人\IdentifyingCode");
        if(!fileDir.exists()){
            fileDir.mkdirs();
        }
        //图片下载保存地址
        File file=new File("E:\钱洋个人\IdentifyingCode\yzm.png");
        if(file.exists()){
            file.delete();
        }
        InputStream input = null;
        FileOutputStream out= null;
        HttpGet httpGet=new HttpGet(src);
        try {
            HttpResponse response=httpClient.execute(httpGet);
            HttpEntity entity = response.getEntity();
            input = entity.getContent();
            int i=-1;
            byte[] byt=new byte[1024];
            out=new FileOutputStream(file);
            while((i=input.read(byt))!=-1){
                out.write(byt);
            }
            System.out.println("图片下载成功!");
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        out.close();
    }
    //登陆后,便可以输入一个或者多个url,进行请求
    public static String gethtml(String redirectLocation) {  
        HttpGet httpget = new HttpGet(redirectLocation);  
        // Create a response handler  
        ResponseHandler<String> responseHandler = new BasicResponseHandler();  
        String responseBody = "";  
        try {  
            responseBody = httpClient.execute(httpget, responseHandler);  
        } catch (Exception e) {  
            e.printStackTrace();  
            responseBody = null;  
        } finally {  
            httpget.abort();  
//            httpClient.getConnectionManager().shutdown();  
        }  
        return responseBody;  
    }  
    //一个实例,只请求了一个url
    public static void main(String[] args) throws ClientProtocolException, IOException {
        loginDouban();
        String redir="https://www.douban.com/people/conanemily/contacts";
//      System.out.println(gethtml(redir));
        String cc=gethtml(redir);
        System.out.println(cc);

    }
}

bb电子糖果派对 2

爬虫布局

bb电子糖果派对 3

关于为什么采用此布局,能够去看自己前段时间写的网络爬虫框架。此程序首即便用来爬取肖似上边那二个网站的新闻。
。蕴涵的信息有:顾客本身的id,客商对应死党的id。将这八个字段写入model

bb电子糖果派对 4

bb电子糖果派对 5

bb电子糖果派对,目录

1   private void Form1_Load(object sender, EventArgs e)
2         {
3             WebAutoLogin.PostLogin("http://www.renren.com/PLogin.do", "niuwenwen668@sina.com", "xxxxxxx");
4             WebAutoLogin.GetPage();
5             WebAutoLogin.GetPage();
6             WebAutoLogin.GetPage();
7             webBrowser1.DocumentText = WebAutoLogin.ResultHtml;
8         }

爬虫实战

  1 using System;
  2 using System.Collections.Generic;
  3 using System.IO;
  4 using System.Linq;
  5 using System.Net;
  6 using System.Text;
  7 using System.Threading.Tasks;
  8 using System.Windows.Forms;
  9 
 10 namespace WebHelp
 11 {
 12     public class WebAutoLogin
 13     {
 14         #region 属性
 15         /// <summary>
 16         /// 登陆后返回的Html
 17         /// </summary>
 18         public static string ResultHtml
 19         {
 20             get;
 21             set;
 22         }
 23         /// <summary>
 24         /// 下一次请求的Url
 25         /// </summary>
 26         public static string NextRequestUrl
 27         {
 28             get;
 29             set;
 30         }
 31         /// <summary>
 32         /// 若要从远程调用中获取COOKIE一定要为request设定一个CookieContainer用来装载返回的cookies
 33         /// </summary>
 34         public static CookieContainer CookieContainer
 35         {
 36             get;
 37             set;
 38         }
 39         /// <summary>
 40         /// Cookies 字符创
 41         /// </summary>
 42         public static string CookiesString
 43         {
 44             get;
 45             set;
 46         }
 47         #endregion
 48 
 49         #region 方法
 50         /// <summary>
 51         /// 用户登陆指定的网站
 52         /// </summary>
 53         /// <param name="loginUrl"></param>
 54         /// <param name="account"></param>
 55         /// <param name="password"></param>
 56         public static void PostLogin(string loginUrl, string account, string password)
 57         {
 58             HttpWebRequest request = null;
 59             HttpWebResponse response = null;
 60             try
 61             {
 62                 string postdata = "email=" + account + "&password="+password+"&origURL=" + "http://www.renren.com/home" + "&domain=renren.com";//模拟请求数据,数据样式可以用FireBug插件得到。
 63                // string LoginUrl = "http://www.renren.com/PLogin.do";
 64                 request = (HttpWebRequest)WebRequest.Create(loginUrl);//实例化web访问类  
 65                 request.Credentials = CredentialCache.DefaultCredentials;
 66                 request.Method = "POST";//数据提交方式为POST  
 67                 request.ContentType = "application/x-www-form-urlencoded";    //模拟头  
 68                 request.AllowAutoRedirect = false;   // 不用需自动跳转
 69                 //必须设置CookieContainer存储请求返回的Cookies
 70                 if (CookieContainer != null)
 71                 {
 72                     request.CookieContainer = CookieContainer;
 73                 }
 74                 else
 75                 {
 76                     request.CookieContainer = new CookieContainer();
 77                     CookieContainer = request.CookieContainer;
 78                 }
 79                 request.KeepAlive = true;
 80                 //提交请求  
 81                 byte[] postdatabytes = Encoding.UTF8.GetBytes(postdata);
 82                 request.ContentLength = postdatabytes.Length;
 83                 Stream stream;
 84                 stream = request.GetRequestStream();
 85                 //设置POST 数据
 86                 stream.Write(postdatabytes, 0, postdatabytes.Length);
 87                 stream.Close();
 88                 //接收响应  
 89                 response = (HttpWebResponse)request.GetResponse();
 90                 //保存返回cookie  
 91                 response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
 92                 CookieCollection cook = response.Cookies;
 93                 string strcrook = request.CookieContainer.GetCookieHeader(request.RequestUri);
 94                 CookiesString = strcrook;
 95                 //取下一次GET跳转地址  
 96                 StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
 97                 string content = sr.ReadToEnd();
 98                 sr.Close();
 99                 request.Abort();
100                 response.Close();
101                 //依据登陆成功后返回的Page信息,求出下次请求的url
102                 //每个网站登陆后加载的Url和顺序不尽相同,以下两步需根据实际情况做特殊处理,从而得到下次请求的URL
103                 string[] substr = content.Split(new char[] { '"' });
104                 NextRequestUrl = substr[1];
105             }
106             catch (WebException ex)
107             {
108                 MessageBox.Show(string.Format("登陆时出错,详细信息:{0}", ex.Message));
109             }
110         }
111         /// <summary>
112         /// 获取用户登陆后下一次请求返回的内容
113         /// </summary>
114         public static void GetPage()
115         {
116             HttpWebRequest request = null;
117             HttpWebResponse response = null;
118             try
119             {
120                 request = (HttpWebRequest)WebRequest.Create(NextRequestUrl);
121                 request.Credentials = CredentialCache.DefaultCredentials;
122                 request.Method = "GET";
123                 request.KeepAlive = true;
124                 request.Headers.Add("Cookie:" + CookiesString);
125                 request.CookieContainer = CookieContainer;
126                 request.AllowAutoRedirect = false;
127                 response = (HttpWebResponse)request.GetResponse();
128                 //设置cookie  
129                 CookiesString = request.CookieContainer.GetCookieHeader(request.RequestUri);
130                 //取再次跳转链接  
131                 StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
132                 string ss = sr.ReadToEnd();
133                 sr.Close();
134                 request.Abort();
135                 response.Close();
136                 //依据登陆成功后返回的Page信息,求出下次请求的url
137                 //每个网站登陆后加载的Url和顺序不尽相同,以下两步需根据实际情况做特殊处理,从而得到下次请求的URL
138                 string[] substr = ss.Split(new char[] { '"' });
139                 NextRequestUrl = substr[1];
140                 ResultHtml = ss;
141             }
142             catch (WebException ex)
143             {
144                 MessageBox.Show(string.Format("获取页面HTML信息出错,详细信息:{0}",ex.Message));
145             }
146         }
147         #endregion
148 
149     }
150 }

解析html(parse)

那部分是瞄准得到的html内容开展剖释,获取客户基友的id。那要接受的不二等秘书技很粗大略,正是Jsoup。

package parse;
import java.util.ArrayList;
import java.util.List;
import model.DouBanUserUrl;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/**
 * @author:合肥工业大学 管理学院 钱洋
 * @email:1563178220@qq.com
 */
public class DouBanParse {
    //将需要返回的数据,保存到List中
    public static List<DouBanUserUrl> getData (String user_id,String html)  {
        List<DouBanUserUrl> DouBanUserUrlData=new ArrayList<DouBanUserUrl>();
        Document doc=Jsoup.parse(html);
        Elements elements=doc.select("dl[class=obu]");
        for (Element ele:elements) {
            String user_contactsid=ele.select("dd").select("a").attr("href").replaceAll("https://www.douban.com/people", "");
            DouBanUserUrl douBanUserUrl=new DouBanUserUrl();
            douBanUserUrl.setUser_id(user_id);
            douBanUserUrl.setUser_contactsid(user_contactsid);
            DouBanUserUrlData.add(douBanUserUrl);
        }
        return DouBanUserUrlData;
    }
}

bb电子糖果派对 6

下一篇:没有了
友情链接: 网站地图
Copyright © 2015-2019 http://www.tk-web.com. bb电子糖果派对有限公司 版权所有