?? jiaoyou.aspx.cs
字號:
?using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Data.Sql;
using System.Data.SqlClient;
public partial class jiaoyou : System.Web.UI.Page
{
int num = 0;
SqlConnection con;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
this.ListBox1.Items.Clear();
ArrayList peoinfo = new ArrayList();
for (int i = int.Parse(this.TextBox1.Text); i <= int.Parse(this.TextBox2.Text); i++)
{
string okurl = this.TextBox3.Text + i.ToString();
HttpWebRequest adsdf = (HttpWebRequest)WebRequest.Create(okurl);
adsdf.Timeout = 10000000;
HttpWebResponse aaaaaaaaa = (HttpWebResponse)adsdf.GetResponse();
Stream strm = aaaaaaaaa.GetResponseStream();
StreamReader sr = new StreamReader(strm, Encoding.GetEncoding("utf-8"));
string dataHTML = sr.ReadToEnd();
StripHTML(dataHTML,i);
strm.Close();
}
this.Label1.Text = num.ToString();
}
public void StripHTML(string strHtml,int he)
{
try
{
string strOutput = strHtml.Substring(strHtml.IndexOf("profile_memberintrop"));
strOutput = strOutput.Substring(0, strOutput.IndexOf("最后登錄"));
int i = strOutput.IndexOf("src=\"http://photo");
int j = strOutput.IndexOf("avatar.jpg") - i;
if (i == -1 || j == -1)
{
}
else
{
string photourl = strOutput.Substring(i + 5, j + 5);//照片
Guid guid = Guid.NewGuid();
WebClient wc = new WebClient();
wc.DownloadFile(photourl, this.TextBox4.Text+guid.ToString()+".jpg");
string name = strHtml.Substring(strHtml.IndexOf("http://images.love21cn.com/w3/profile/i/"));
name = name.Substring(0, name.IndexOf("</strong>"));
int k = name.IndexOf(">");
string phoname = name.Substring(k+1).Trim(); //人名
this.ListBox1.Items.Add(photourl + " " + phoname+" "+" "+he);
string info = strHtml.Substring(strHtml.IndexOf("<dl class=\"profile_memberintrot\">"));
info = info.Substring(0, info.IndexOf("信用等級"));
string useinfo = "";
Regex regex = new Regex(@"<([\S\s]*?)>");//[^\x00-\xff]
MatchCollection matches = regex.Matches(info);
System.Collections.IEnumerator enu = matches.GetEnumerator();
while (enu.MoveNext() && enu.Current != null)
{
Match match = (Match)(enu.Current);
info = info.Remove(info.IndexOf(match.Value),match.Value.Length); //人員信息
}
useinfo = info;
string testsex = useinfo.Substring(0, useinfo.IndexOf("年齡"));
string[] usetestsex = testsex.Split(':');
string sex = usetestsex[1].Trim(); //性別
string testage = useinfo.Substring(useinfo.IndexOf("年齡"), useinfo.IndexOf("歲") - useinfo.IndexOf("年齡"));
string[] usetestage = testage.Split(':');
string age = usetestage[1].Trim(); //年齡
string testheight = useinfo.Substring(useinfo.IndexOf("身高"), useinfo.IndexOf("厘米") - useinfo.IndexOf("身高"));
string[] usetestheight = testheight.Split(':');
string height = usetestheight[1].Trim(); //身高
string testqua = useinfo.Substring(useinfo.IndexOf("學歷"), useinfo.IndexOf("民族") - useinfo.IndexOf("學歷"));
string[] usetestqua = testqua.Split(':');
string qua = usetestqua[1].Trim(); //學歷
string testnat = useinfo.Substring(useinfo.IndexOf("民族"), useinfo.IndexOf("所在地區") - useinfo.IndexOf("民族"));
string[] usetestnat = testnat.Split(':');
string nat = usetestnat[1].Trim(); //民族
string testjob = useinfo.Substring(useinfo.IndexOf("職業"), useinfo.IndexOf("婚姻") - useinfo.IndexOf("職業"));
string[] usetestjob = testjob.Split(':');
string job = usetestjob[1].Trim(); //職業
string testmarr = useinfo.Substring(useinfo.IndexOf("婚姻"),11);
string[] usetestmarr = testmarr.Split(':');
string marr = usetestmarr[1].Trim(); //婚姻
string liuyan = strHtml.Substring(strHtml.IndexOf("內心獨白"));
liuyan = liuyan.Substring(0, liuyan.IndexOf("</dl>"));
string liuyaninfo = "";
Regex regex1 = new Regex(@"<([\S\s]*?)>"); //[^\x00-\xff]
MatchCollection matches1 = regex1.Matches(liuyan);
System.Collections.IEnumerator enu1 = matches1.GetEnumerator();
while (enu1.MoveNext() && enu1.Current != null)
{
Match match1 = (Match)(enu1.Current);
liuyan = liuyan.Remove(liuyan.IndexOf(match1.Value), match1.Value.Length); //留言
}
liuyaninfo = liuyan;
string endneirong = liuyaninfo.Substring(liuyaninfo.IndexOf("佳緣標簽"));
string testintrod = endneirong.Substring(0,endneirong.IndexOf("心中的"));
string[] usetestintrod = testintrod.Split(':');
string introd = ""; //個人簡介
if (usetestintrod[1].IndexOf("佳緣標簽") != -1)
{
introd = usetestintrod[1].Trim().Replace("佳緣標簽", "個人信息");
}
else
{
introd = usetestintrod[1].Trim();
}
string testfriend = endneirong.Substring(endneirong.IndexOf("心中的"));
string[] usetestfriend = testfriend.Split(':');
string friend = usetestfriend[1].Trim(); //理想對象
num++;
string sql = string.Format("insert into love_main (username,password,sex,age,nat,love,height_,edu,field,aboutus,lxdx) values ('{0}','1234567','{1}',{2},'{3}','{4}',{5},'{6}','{7}','{8}','{9}')", phoname,sex,age,nat,marr,height,qua,job,introd,friend);
insertdata(sql);
}
}
catch
{
this.Label1.Text = "第 " + he.ToString() + " 數據出現異常";
}
}
public bool openDB()
{
try
{
con = new SqlConnection("server=192.168.1.228;database=yzlove;uid=sa;pwd=sa");
con.Open();
return true;
}
catch
{
}
return false;
}
public void insertdata(string sql)
{
if (openDB())
{
com = new SqlCommand();
com.Connection = con;
com.CommandText = sql;
com.ExecuteNonQuery();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -