网站自动注册(winform、webBrowser)

ContractedBlock.gif ExpandedBlockStart.gif Code
  private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
{

            
if (webBrowser1.Url.ToString() == "http://xxxxx/xxxx.xxx.cn/")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                StreamReader sr 
= new StreamReader(Application.StartupPath + "\\cont.txt");
                i 
= int.Parse(sr.ReadLine().ToString());
                
string name = "";
                sr.Close();
                HtmlDocument doc 
= webBrowser1.Document;
                HtmlElement btn 
= null;
                
foreach (HtmlElement em in doc.All)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
string str = em.Name;
                    
switch (str)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
case "email"{ em.SetAttribute("value""aajyjc" + i.ToString()); name = "gzjyj" + i.ToString(); }break;
                        
case "passwd": em.SetAttribute("value""111111"); break;
                        
case "againpasswd": em.SetAttribute("value""111111"); break;
                        
case "question": em.SetAttribute("value""1"); break;
                        
case "answer": em.SetAttribute("value""呜呜呜呜"); break;
                        
case "birthday": em.SetAttribute("value""1987-10-05"); break;
                        
case "pnickname": em.SetAttribute("value""通天塔"); break;
                        
case "securityemail": em.SetAttribute("value""abc@def.com"); break;
                        
case "ptruename": em.SetAttribute("value""地方"); break;
                        
case "idno": em.SetAttribute("value", getRandom2(System.DateTime.Now.Second)); break;
                        
case "ppostcode": em.SetAttribute("value", getRandom1()); break;
                        
case "ppostaddress": em.SetAttribute("value""份额为服务俄方"); break;
                        
case "FormSubmit": btn = em; break;
                        
defaultbreak;
                    }

                }

                i
++;
                StreamWriter sw 
= new StreamWriter(Application.StartupPath + "\\cont.txt");
                sw.WriteLine(i);
                sw.Close();
                            }
}

 

上面的代码是对网站里面要填的项进行自动填写。

下面是 用代理服务器登陆 代码 ,下面的代码不是自己写的,网上找的。

 

ContractedBlock.gif ExpandedBlockStart.gif Code
//这里是调用
WebBrowser wb = new WebBrowser();
WindowsFormsApplication1.proxy py1 
= new proxy();
py1.RefreshIESettings(
"222.168.6.226:8080");
System.Object nullObject 
= 0;
string strTemp = String.Empty;
System.Object nullObjStr 
= strTemp;
wb.Navigate(
"http://xxxxx.com");
//这里是调用的类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
ExpandedBlockStart.gifContractedBlock.gif
{
    
class proxy
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{

        
public struct Struct_INTERNET_PROXY_INFO
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
public int dwAccessType;
            
public IntPtr proxy;
            
public IntPtr proxyBypass;
        }
;
        [DllImport(
"wininet.dll", SetLastError = true)]
        
private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
        
        
public void RefreshIESettings(string strProxy)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
const int INTERNET_OPTION_PROXY = 38;
            
const int INTERNET_OPEN_TYPE_PROXY = 3;
            Struct_INTERNET_PROXY_INFO struct_IPI;
            
// Filling in structure
            struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
            struct_IPI.proxy 
= Marshal.StringToHGlobalAnsi(strProxy);
            struct_IPI.proxyBypass 
= Marshal.StringToHGlobalAnsi("local");
            
// Allocating memory
            IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));
            
// Converting structure to IntPtr
            Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
            
bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
        }

    }


}



 

下面是 遇见 网页中提交项 的自动提交实现代码

 

ContractedBlock.gif ExpandedBlockStart.gif Code
if (webBrowser1.Url.ToString() == "http://login.jyb.cn/user_mod.php")
ExpandedBlockStart.gifContractedBlock.gif            
{
                HtmlDocument doc 
= webBrowser1.Document;
                
foreach (HtmlElement em in doc.All)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{

                    
string str = em.Name;
                    
switch (str)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
case "mobile"{ em.SetAttribute("value", getRandom3(System.DateTime.Now.Second)); }break;

                        
defaultbreak;
                    }

                }

                HtmlElement form 
= this.webBrowser1.Document.Forms[0];
                form.InvokeMember(
"submit");
            }

 

随机用户名的代码(当然这里没有考虑,用户名的第一位不能为数字的情况)

 

 

ContractedBlock.gif ExpandedBlockStart.gif Code
  private string CreateRandomCode(int codeCount)
ExpandedBlockStart.gifContractedBlock.gif        
{
            
string allChar = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9";
            
string[] allCharArray = allChar.Split(',');
            
string randomCode = "";
            
int temp = -1;

            Random rand 
= new Random();
            
for (int i = 0; i < codeCount; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
if (temp != -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    rand 
= new Random(i * temp * ((int)DateTime.Now.Ticks));
                }

                
int t = rand.Next(35);
                
if (temp == t)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
return CreateRandomCode(codeCount);
                }

                temp 
= t;
                randomCode 
+= allCharArray[t];
            }

            
return randomCode;
        }

 

 

转载于:https://www.cnblogs.com/cjzttt/archive/2009/10/23/1588724.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值