博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
test
阅读量:6439 次
发布时间:2019-06-23

本文共 3795 字,大约阅读时间需要 12 分钟。

using System;using System.Data;using System.Configuration;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.Text.RegularExpressions;using System.Collections;using System.Collections.Generic;using System.Net;using System.IO;public partial class _Default : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if (!Page.IsPostBack)        {            InitData();        }    }    protected void btnCollect_Click(object sender, EventArgs e)    {        string strUrl = txtCollectionUrl.Text.Trim();        List
urls = new List
(); List
serialsStrings = new List
(); Dictionary
dic = new Dictionary
(); int iStart = 0; int iEnd = 0; if (string.IsNullOrEmpty(strUrl)) return; string hasPattern = @"{*}"; Regex reg = new Regex(hasPattern, RegexOptions.Compiled | RegexOptions.Singleline); if (reg.IsMatch(strUrl)) { int.TryParse(txtStart.Text.Trim(), out iStart); int.TryParse(txtEnd.Text.Trim(), out iEnd); serialsStrings = GetSerialStrings(iStart, iEnd, Convert.ToInt32(ddlSimilarCount.SelectedValue)); foreach (string var in serialsStrings) { urls.Add(strUrl.Replace(hasPattern,var)); } } else { urls.Add(strUrl); } foreach (string var in urls) { Response.Write(var + "
"); } foreach (string var in urls) { WebRequest request = WebRequest.Create(var); WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default); string strContent = reader.ReadToEnd(); string strContentPattern = txtPrefixRule.Text + @".*?" + txtSuffixRule.Text; Regex regContent = new Regex(strContentPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); MatchCollection mc = regContent.Matches(strContent); foreach (Match match in mc) { //Response.Write(match.Value); dic["Issue"] = GetContent(match.Value, txtPrefixIssueRule.Text, txtSubffixIssueRule.Text); dic["Lottery"] = GetContent(match.Value, txtPrefixLotteryRule.Text, txtSubffixLotteryRule.Text); dic["Result"] = GetContent(match.Value, txtPrefixResultRule.Text, txtSubffixResultRule.Text); dic["SaleRoom"] = GetContent(match.Value, txtPrefixSaleRoomRule.Text, txtSubffixSaleRoomRule.Text); dic["Date"] = GetContent(match.Value, txtPrefixDateRule.Text, txtSubffixDateRule.Text); } } foreach (object var in collection_to_loop) { } } private string GetContent(string content, string startStr, string endStr) { string result = string.Empty; int indexA = content.IndexOf(startStr); int indexB = content.IndexOf(endStr); if (indexA > -1 && indexB > -1) { if (indexA > indexB) { indexB = content.IndexOf(endStr, indexA); //indexA = 0; } if (indexB > -1) result = content.Substring(indexA + startStr.Length, indexB - indexA - startStr.Length); } return result; } private void InitData() { this.txtStart.Text = "0"; this.txtEnd.Text = "0"; for (int i = 1; i <= 5; i++) { ddlSimilarCount.Items.Add(new ListItem(i.ToString(), i.ToString())); } ddlSimilarCount.SelectedValue = "2"; } private List
GetSerialStrings(int iStart, int iEnd, int length) { int iTempStart = iStart; int iTempEnd = iEnd; List
serialStrings = new List
(); if (iStart > iEnd) { iTempStart = iEnd; iTempEnd = iStart; } if (iTempEnd.ToString().Length > length) length = iTempEnd.ToString().Length; int iCount = iTempEnd - iTempStart; for (int i = iTempStart; i <= iTempEnd; i++) { serialStrings.Add(i.ToString().PadLeft(length, '0')); } return serialStrings; }}
转载请注明出处[ ] 
作者赞赏
 
刚做的招标网:  请大家多意见
本文转自Sam Lin博客博客园博客,原文链接:http://www.cnblogs.com/samlin/archive/2008/12/01/1345302.html,如需转载请自行联系原作者
你可能感兴趣的文章
定时管理器框架-Task.MainForm
查看>>
[python]使用virtualenvWrapper
查看>>
用Aspose.Cells控件读取Excel
查看>>
TCP三次握手四次挥手相关问题探讨
查看>>
iOS 独立开发记录(上)
查看>>
How to add elements to a List in Scala
查看>>
一起学微软Power BI系列-官方文档-入门指南(4)Power BI的可视化
查看>>
Android.util.Log 关于Android开发中打印log
查看>>
转:Python yield 使用浅析 from IBM Developer
查看>>
仪表板颜色
查看>>
NodeJS、NPM安装配置步骤(windows版本)
查看>>
mysql oom之后的page 447 log sequence number 292344272 is in the future
查看>>
chrome禁用某个网站js脚本的执行
查看>>
数组排序 和 二分法查找
查看>>
MongoDB C Driver Building on Windows
查看>>
备忘zookeeper(单机+伪集群+集群)
查看>>
无需编译、快速生成 Vue 风格的文档网站
查看>>
AtomicBoolean介绍与使用
查看>>
Elasticsearch之curl删除
查看>>
Apache Spark 内存管理详解(转载)
查看>>