通过正则表达式来分析网站云商网(http://www.ynshangji.com/h738573/)的页面联系方式
[C#] 纯文本查看 复制代码 Thread pingTask = new Thread(new ThreadStart(delegate
{
//http://www.ynshangji.com/h738573/
int s = Convert.ToInt32(txtsnumber.Text.Trim());
int t = Convert.ToInt32(txtnumber.Text.Trim());
int yy = Convert.ToInt32(txtnumber.Text.Trim());
for (int i = s; i <= t; i++)
{
txturl.Text = $"http://www.ynshangji.com/h{i.ToString()}/";
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = txturl.Text.Trim()
};
HttpResult result = http.GetHtml(item);
richTextBox1.Text = result.Html;
string comname = Regex.Match(result.Html, "<li><i>公司名称</i>(.*?)</li>").Groups[1].Value.Trim().Replace(" ", string.Empty).Replace(" ", string.Empty);
richTextBox1.Text = $"企业名:{ comname}\r\n{richTextBox1.Text}";
string comtell = Regex.Match(result.Html, "<li><i>联系手机</i>(.*?)</li>").Groups[1].Value.Trim().Replace(" ", string.Empty);
richTextBox1.Text = $"联系电话:{ comtell}\r\n{richTextBox1.Text}";
if (string.IsNullOrWhiteSpace(comtell))
{
comtell = Regex.Match(result.Html, "<li><i>联系电话</i>(.*?)</li>").Groups[1].Value.Trim().Replace(" ", string.Empty);
}
string comaddress = Regex.Match(result.Html, "<li><i>公司地址</i>(.*?)</li>").Groups[1].Value.Trim().Replace(" ", string.Empty);
richTextBox1.Text = $"联系地址:{ comaddress}\r\n{richTextBox1.Text}";
//"duty":"\w+"
string comren = Regex.Match(result.Html, "<li><i>联系人</i>(.*?)</li>").Groups[1].Value.Trim().Replace(" ", string.Empty).Replace(" ", string.Empty);
richTextBox1.Text = $"联系人:{ comren}\r\n{richTextBox1.Text}";
try
{
if (string.IsNullOrWhiteSpace(comtell) || comtell.Contains("未提供") || comtell.Contains("合责约见"))
{
richTextBox1.Text += $"写入失败\r\n{ richTextBox1.Text}";
}
else
{
com_infoBLL infobll = new com_infoBLL();
com_info info = new com_info()
{
comname = comname,
fadingdaibiao = string.Empty,
email = string.Empty,
mobile = string.Empty,
zhuceaddress = comaddress,
unionid = txturl.Text,
sourcetype = 15,
};
if (infobll.Count("comname='" + comname + "'") > 0)
{
richTextBox1.Text = $"重复企业:\r\n{richTextBox1.Text}";
}
else
{
comname = Regex.Match(result.Html, "<li><i>公司名称</i>(.*?)</li>").Groups[1].Value.Trim().Replace(" ", string.Empty).Replace(" ", string.Empty);
richTextBox1.Text = $"企业名:{ comname}\r\n{richTextBox1.Text}";
comtell = Regex.Match(result.Html, "<li><i>联系手机</i>(.*?)</li>").Groups[1].Value.Trim().Replace(" ", string.Empty);
richTextBox1.Text = $"联系电话:{ comtell}\r\n{richTextBox1.Text}";
if (string.IsNullOrWhiteSpace(comtell))
{
comtell = Regex.Match(result.Html, "<li><i>联系电话</i>(.*?)</li>").Groups[1].Value.Trim().Replace(" ", string.Empty);
}
comaddress = Regex.Match(result.Html, "<li><i>公司地址</i>(.*?)</li>").Groups[1].Value.Trim().Replace(" ", string.Empty);
richTextBox1.Text = $"联系地址:{ comaddress}\r\n{richTextBox1.Text}";
//"duty":"\w+"
comren = Regex.Match(result.Html, "<li><i>联系人</i>(.*?)</li>").Groups[1].Value.Trim().Replace(" ", string.Empty).Replace(" ", string.Empty);
richTextBox1.Text = $"联系人:{ comren}\r\n{richTextBox1.Text}";
//写入数据库
richTextBox1.Text = $"联系方式{id}写入数据库状态:{mobilebll.insert(mobileinfo)} 写入也成功\r\n{richTextBox1.Text}";
}
}
}
}
catch (Exception ex)
{
richTextBox1.Text = ex.Message + richTextBox1.Text;
}
//Thread.Sleep(2000);
}
}));
pingTask.Start();
|