zoukankan      html  css  js  c++  java
  • 无聊,写个小程序刷iPhone4

    官网上的iPhone4,便宜,但不好得

    本人不是果粉,但也幻想弄上一个两个倒手赚点小钱

    总刷网页太麻烦

    自己写个App吧

    很简单的应用

    思路,官网上正常情况下有两个 iPhone4的“暂无供应”,只要查到有两个这种字符串,就是没放出,否则呢,嘿嘿。。。

    窗体设计部分:

    代码
    namespace IP4Killer
    {
        
    partial class Form1
        {
            
    /// <summary>
            
    /// Required designer variable.
            
    /// </summary>
            private System.ComponentModel.IContainer components = null;

            
    /// <summary>
            
    /// Clean up any resources being used.
            
    /// </summary>
            
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                
    if (disposing && (components != null))
                {
                    components.Dispose();
                }
                
    base.Dispose(disposing);
            }

            
    #region Windows Form Designer generated code

            
    /// <summary>
            
    /// Required method for Designer support - do not modify
            
    /// the contents of this method with the code editor.
            
    /// </summary>
            private void InitializeComponent()
            {
                
    this.components = new System.ComponentModel.Container();
                System.ComponentModel.ComponentResourceManager resources 
    = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
                
    this.linkLabel1 = new System.Windows.Forms.LinkLabel();
                
    this.label1 = new System.Windows.Forms.Label();
                
    this.linkLabel2 = new System.Windows.Forms.LinkLabel();
                
    this.label2 = new System.Windows.Forms.Label();
                
    this.linkLabel3 = new System.Windows.Forms.LinkLabel();
                
    this.label3 = new System.Windows.Forms.Label();
                
    this.linkLabel4 = new System.Windows.Forms.LinkLabel();
                
    this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
                
    this.SuspendLayout();
                
    // 
                
    // linkLabel1
                
    // 
                this.linkLabel1.AutoSize = true;
                
    this.linkLabel1.Location = new System.Drawing.Point(129);
                
    this.linkLabel1.Name = "linkLabel1";
                
    this.linkLabel1.Size = new System.Drawing.Size(7712);
                
    this.linkLabel1.TabIndex = 0;
                
    this.linkLabel1.TabStop = true;
                
    this.linkLabel1.Text = "Printf@Soway";
                
    // 
                
    // label1
                
    // 
                this.label1.AutoSize = true;
                
    this.label1.Location = new System.Drawing.Point(4282);
                
    this.label1.Name = "label1";
                
    this.label1.Size = new System.Drawing.Size(5912);
                
    this.label1.TabIndex = 1;
                
    this.label1.Text = "开始时间:";
                
    // 
                
    // linkLabel2
                
    // 
                this.linkLabel2.AutoSize = true;
                
    this.linkLabel2.Location = new System.Drawing.Point(10882);
                
    this.linkLabel2.Name = "linkLabel2";
                
    this.linkLabel2.Size = new System.Drawing.Size(6512);
                
    this.linkLabel2.TabIndex = 2;
                
    this.linkLabel2.TabStop = true;
                
    this.linkLabel2.Text = "linkLabel2";
                
    // 
                
    // label2
                
    // 
                this.label2.AutoSize = true;
                
    this.label2.Location = new System.Drawing.Point(44118);
                
    this.label2.Name = "label2";
                
    this.label2.Size = new System.Drawing.Size(5912);
                
    this.label2.TabIndex = 3;
                
    this.label2.Text = "刷新次数:";
                
    // 
                
    // linkLabel3
                
    // 
                this.linkLabel3.AutoSize = true;
                
    this.linkLabel3.Location = new System.Drawing.Point(108118);
                
    this.linkLabel3.Name = "linkLabel3";
                
    this.linkLabel3.Size = new System.Drawing.Size(6512);
                
    this.linkLabel3.TabIndex = 4;
                
    this.linkLabel3.TabStop = true;
                
    this.linkLabel3.Text = "linkLabel3";
                
    // 
                
    // label3
                
    // 
                this.label3.AutoSize = true;
                
    this.label3.Location = new System.Drawing.Point(42153);
                
    this.label3.Name = "label3";
                
    this.label3.Size = new System.Drawing.Size(5912);
                
    this.label3.TabIndex = 5;
                
    this.label3.Text = "秒杀次数:";
                
    // 
                
    // linkLabel4
                
    // 
                this.linkLabel4.AutoSize = true;
                
    this.linkLabel4.Location = new System.Drawing.Point(108153);
                
    this.linkLabel4.Name = "linkLabel4";
                
    this.linkLabel4.Size = new System.Drawing.Size(6512);
                
    this.linkLabel4.TabIndex = 6;
                
    this.linkLabel4.TabStop = true;
                
    this.linkLabel4.Text = "linkLabel4";
                
    // 
                
    // notifyIcon1
                
    // 
                this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
                
    this.notifyIcon1.Text = "iPhone4 秒杀器";
                
    this.notifyIcon1.Visible = true;
                
    this.notifyIcon1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseClick);
                
    // 
                
    // Form1
                
    // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                
    this.ClientSize = new System.Drawing.Size(284262);
                
    this.Controls.Add(this.linkLabel4);
                
    this.Controls.Add(this.label3);
                
    this.Controls.Add(this.linkLabel3);
                
    this.Controls.Add(this.label2);
                
    this.Controls.Add(this.linkLabel2);
                
    this.Controls.Add(this.label1);
                
    this.Controls.Add(this.linkLabel1);
                
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
                
    this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
                
    this.MaximizeBox = false;
                
    this.Name = "Form1";
                
    this.Text = "iPhone4秒杀器";
                
    this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
                
    this.Load += new System.EventHandler(this.Form1_Load);
                
    this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
                
    this.ResumeLayout(false);
                
    this.PerformLayout();

            }

            
    #endregion

            
    private System.Windows.Forms.LinkLabel linkLabel1;
            
    private System.Windows.Forms.Label label1;
            
    private System.Windows.Forms.LinkLabel linkLabel2;
            
    private System.Windows.Forms.Label label2;
            
    private System.Windows.Forms.LinkLabel linkLabel3;
            
    private System.Windows.Forms.Label label3;
            
    private System.Windows.Forms.LinkLabel linkLabel4;
            
    private System.Windows.Forms.NotifyIcon notifyIcon1;

        }
    }

    逻辑部分:

    代码
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Text.RegularExpressions;

    namespace IP4Killer
    {
        
    public partial class Form1 : Form
        {
            
    public Form1()
            {
                InitializeComponent();
            }

            
    private void button1_Click(object sender, EventArgs e)
            {
               
                 
            }

            
    bool Run = false;

            
    int FreshTimes = 0;
            
    int OKTimes = 0;

            
    private  Encoding GetEncoding(string html) 

    string pattern = @"(?i)\bcharset=(?<charset>[-a-zA-Z_0-9]+)"
    string charset = Regex.Match(html, pattern).Groups["charset"].Value; 
    try { return Encoding.GetEncoding(charset); } 
    catch (ArgumentException) { return null; } 


     
            
    private System.Text.Encoding GetPageEncoding(string url)
            {
                System.Text.Encoding encod 
    = System.Text.Encoding.UTF8;
                
    try
                {
                    System.Net.WebRequest request 
    = System.Net.WebRequest.Create(url);
                    System.Net.WebResponse response 
    = request.GetResponse();
                    var i 
    = response.Headers.AllKeys;
                    System.IO.Stream stream 
    = response.GetResponseStream();
                    
    byte[] header = new byte[1024];
                    stream.Read(header, 
    0, header.Length);
                    
    string head = Encoding.Default.GetString(header);
                    stream.Close(); stream.Dispose();
                    
    string patternEncode = @"(?i)\bcharset=(?<charset>[-a-zA-Z_0-9]+)";
                    Regex regEncode 
    = new Regex(patternEncode, RegexOptions.IgnoreCase);
                    Match match 
    = regEncode.Match(head); 
                    
    if (match.Success) {
                        encod 
    = System.Text.Encoding.GetEncoding(match.Groups["charset"].Value);
                    }
                }
                
    catch { } return encod;

            }

            
    private void Work()
            {
                Run 
    = true;
                 String url 
    = "http://store.apple.com/cn/browse/home/shop_iphone/family/iphone";

                System.Net.WebClient aWebClient 
    = new System.Net.WebClient();
                aWebClient.Encoding 
    = GetPageEncoding(url);
               


                String Current 
    = "";
                String Last 
    = "";
                
    int Times = 1;
              
            
                
    int temp = 0;
                
    while (Run)
                {
                    Current  
    = aWebClient.DownloadString("http://store.apple.com/cn/browse/home/shop_iphone/family/iphone");
                   
    // Match match = regEncode.Match(Current);


                
                    String[] strs 
    = Current.Split(new String[] { "暂无供应" }, StringSplitOptions.RemoveEmptyEntries);
                    
    //var current = strs.Length;
                    if(strs.Length != temp )
                       
                    {

                        
    if (temp != 0)
                        {


                            OKTimes
    ++;
                            
    try
                            {

                                System.Diagnostics.Process.Start(url);
                                System.IO.File.WriteAllLines(System.DateTime.Now.ToString(
    "yyyy年MM月dd日HHmmss_"+ OKTimes.ToString() + ".html"new String[] { Current });
                            }
                            
    catch { }
                        }
                        temp  
    = strs.Length;

                    }
                    
             
                    FreshTimes 
    ++;
                    
                    
    if(Run)

                    
    this.Invoke(new doo(this.updateTimes));


                }

            }

            
    private void Form1_Load(object sender, EventArgs e)
            {
                
    this.linkLabel2.Text = System.DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss");
                updateTimes();
                 
                
    new System.Threading.Thread(new System.Threading.ThreadStart(Work)).Start();
            }

            
    private delegate void  doo ();
            
    private void updateTimes()
            {
                
    try
                {
                    linkLabel3.Text 
    = FreshTimes.ToString();
                    linkLabel4.Text 
    = OKTimes.ToString();
                    
    this.notifyIcon1.Text = "刷新:" + FreshTimes.ToString() + "次,秒杀:" + OKTimes.ToString();
                }
                
    catch { }

            }
            
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                Run 
    = false;
            }

            
    private void Form1_SizeChanged(object sender, EventArgs e)
            {
                
    switch (this.WindowState)
                {
                    
    case FormWindowState.Normal:
                        
    this.notifyIcon1.Visible = false;
                        
    this.ShowInTaskbar = true;
                        
    break;
                    
    case FormWindowState.Minimized:
                        
    this.notifyIcon1.Visible = true;
                        
    this.ShowInTaskbar = false;
                        
    break;
                    
    case FormWindowState.Maximized:
                        
    this.notifyIcon1.Visible = false;
                        
    this.ShowInTaskbar = true;
                        
    break;
                }
            }

            
    private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
            {
                
    this.WindowState = FormWindowState.Normal;
            }
        }
    }
  • 相关阅读:
    B01-java学习-阶段2-面向对象
    A11-java学习-二维数组-面向对象概念-类的编写-测试类的编写-创建对象-使用对象-递归
    09-java学习-数组-冒泡排序-选择排序-数组工具类编写-查找-扩容
    08-java学习-数组-增强for循环-数组与方法-main函数参数
    07-java学习-方法重载-idea集成开发工具学习-项目-模块-包
    执行SQL语句---SELECT
    执行SQL语句---INSERT/UPDATE/DELETE
    undefined reference to `mysql_init'解决办法
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    网络编程(三)---数据报套接字
  • 原文地址:https://www.cnblogs.com/geyunfei/p/1898759.html
Copyright © 2011-2022 走看看