⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 可以抓取淘宝上的所有商家信息 一般情况下可以把商家信息抓取后
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 抓淘宝商家
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Button button2;

		System.Threading.Thread thd=null;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		System.Threading.Thread thd2=null;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.button2 = new System.Windows.Forms.Button();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(240, 16);
			this.button1.Name = "button1";
			this.button1.TabIndex = 0;
			this.button1.Text = "button1";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 64);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(536, 23);
			this.label1.TabIndex = 1;
			this.label1.Text = "label1";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 96);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(80, 23);
			this.label2.TabIndex = 2;
			this.label2.Text = "label2";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(144, 96);
			this.label3.Name = "label3";
			this.label3.TabIndex = 3;
			this.label3.Text = "label3";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(8, 136);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(472, 23);
			this.label4.TabIndex = 4;
			this.label4.Text = "label4";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(304, 104);
			this.label5.Name = "label5";
			this.label5.TabIndex = 5;
			this.label5.Text = "label5";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(456, 24);
			this.label6.Name = "label6";
			this.label6.TabIndex = 6;
			this.label6.Text = "label6";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(472, 96);
			this.label7.Name = "label7";
			this.label7.TabIndex = 7;
			this.label7.Text = "label7";
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(256, 176);
			this.button2.Name = "button2";
			this.button2.TabIndex = 8;
			this.button2.Text = "button2";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(368, 184);
			this.label8.Name = "label8";
			this.label8.TabIndex = 9;
			this.label8.Text = "label8";
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(504, 184);
			this.label9.Name = "label9";
			this.label9.TabIndex = 10;
			this.label9.Text = "label9";
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(64, 184);
			this.label10.Name = "label10";
			this.label10.TabIndex = 11;
			this.label10.Text = "0";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(576, 222);
			this.Controls.Add(this.label10);
			this.Controls.Add(this.label9);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.button1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		#region 搜索指定的栏目
		private void button1_Click(object sender, System.EventArgs e)
		{
			thd=new System.Threading.Thread(new System.Threading.ThreadStart(startThd));
			thd.Start();
		}

		private void startThd()
		{
			System.IO.StreamReader sr=new System.IO.StreamReader("aaa.txt",System.Text.Encoding.GetEncoding("gb2312"));
			string str=sr.ReadLine();
			while(str!=null)
			{
				//http://favorite.taobao.com/collect_channel-0-hot---NN-40--36--14-.htm**38**女装/女士精品
				int len=str.IndexOf("**");
				string url="";
				int allPage=0;
				string type="";
				if(len>0)
				{
					url=str.Substring(0,len);
					str=str.Substring(len+2);
					label1.Text=url;
					len=str.IndexOf("**");
					if(len>0)
					{
						allPage=int.Parse(str.Substring(0,len));
						//...
						type=str.Substring(len+2);
						BaseInfo.GetInfo.SetType(type);
						//..............
						label2.Text=allPage.ToString();
						label3.Text=type;

						if(url.IndexOf("NN")>0)
						{
							for(int i=0;i<allPage;i++)
							{
								string[] newList=new string[100];
								label5.Text=i.ToString();
								string newUrl=url.Replace("NN",(i*40).ToString());
								string webInfo=BaseInfo.webInfo.getwebInfo(newUrl);
								newList=BaseInfo.GetInfo.GetAllList(webInfo);
								
								for(int j=0;j<newList.Length;j++)
								{
									if(newList[j]==null) break;
									if(newList[j].Length==0) break;
									label4.Text=newList[j];
									if(BaseInfo.GetInfo.SetUser(type,newList[j]))
									{
										label7.Text="成功";
									}
									else
									{
										label7.Text="失败";
										System.Threading.Thread.Sleep(50);
									}
									label6.Text=(j+1).ToString();
									System.Threading.Thread.Sleep(10);
								}
							}
						}
						else
						{
							//........只有一页
							string webInfo=BaseInfo.webInfo.getwebInfo(url);
							label5.Text="0";
						
							string[] newList=BaseInfo.GetInfo.GetAllList(webInfo);
							for(int j=0;j<newList.Length;j++)
							{
								if(newList[j]==null) break;
								if(newList[j].Length==0) break;
								label4.Text=newList[j];
								BaseInfo.GetInfo.SetUser(type,newList[j]);
								System.Threading.Thread.Sleep(100);
							}
						}
					}

				}


				str=sr.ReadLine();
			}

		}

		#endregion
		#region 搜索出来的卖家信息
		private void button2_Click(object sender, System.EventArgs e)
		{
			thd2=new System.Threading.Thread(new System.Threading.ThreadStart(startThd2));
			thd2.Start();
		}
		private void startThd2()
		{
			System.IO.StreamReader sr=new System.IO.StreamReader("bbb.txt",System.Text.Encoding.GetEncoding("gb2312"));
			string str=sr.ReadLine();
			while(str!=null)
			{
				//http://favorite.taobao.com/collect_channel-1-hot---NN-40--36--16-.htm**女装/女士精品**100
				int len=str.IndexOf("**");
				string url="";
				int allPage=0;
				string type="";
				try
				{
					if(len>0)
					{
						url=str.Substring(0,len);
						str=str.Substring(len+2);
						label1.Text=url;
						len=str.IndexOf("**");
						if(len>0)
						{
							type=str.Substring(0,len);
							//...
							allPage=int.Parse(str.Substring(len+2));
							BaseInfo.GetInfo.SetType(type);
							//..............
							label2.Text=allPage.ToString();
							label3.Text=type;

							if(url.IndexOf("NN")>0)
							{
								#region ddd
								for(int i=0;i<allPage;i++)
								{
									try
									{
										string[] newList=new string[100];
										string[] newGoods=new string[100];
										label5.Text=i.ToString();
										string newUrl=url.Replace("NN",(i*40).ToString());
										string webInfo=BaseInfo.webInfo.getwebInfo(newUrl);
										newList=BaseInfo.GetInfo.GetAllList2(webInfo);
										newGoods=BaseInfo.GetInfo.GetAllGoods(webInfo);
										#region 2
										for(int j=0;j<newList.Length;j++)
										{
											if(newList[j]==null) break;
											if(newList[j].Length==0) break;
											label4.Text=newList[j];
											if(BaseInfo.GetInfo.SetUser(type,newList[j]))
											{
												label7.Text="成功";
											}
											else
											{
												label7.Text="失败";
												System.Threading.Thread.Sleep(50);
											}
											label6.Text=(j+1).ToString();
											System.Threading.Thread.Sleep(10);
										}
										#endregion
										//............根据产品得出产品中出现的买家
										for(int j=0;j<newGoods.Length;j++)
										{
											#region d
											if(newGoods[j]==null) break;
											if(newGoods[j].Length==0) break;
											//....................
											string goodsTemp=newGoods[j];
											webInfo=BaseInfo.webInfo.getwebInfo(goodsTemp);
											//.............
											string[] userInfo=BaseInfo.GetStr.GetGoodsInfo(webInfo);
											//..
											for(int kk=0;kk<userInfo.Length;kk++)
											{
												if(userInfo[kk]==null) break;
												if(userInfo[kk].Length==0) break;
												label8.Text=userInfo[kk];
												if(userInfo[kk].IndexOf("*")>0)
												{
													;
												}
												else
												{
													if(BaseInfo.GetInfo.SetUser2(type,userInfo[kk]))
													{
														label9.Text="ok";
													}
													else
													{
														label9.Text="no";
													}
												}
												System.Threading.Thread.Sleep(50);
											}
											System.Threading.Thread.Sleep(50);
											#endregion

										}
									}
									catch{;}
								}
								#endregion
							}
						
						}

					}
				}
				catch{;}


				str=sr.ReadLine();
			}

		}


		#endregion

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -