网页信息抓取

hbsyhx hbsyhx 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
已经获得了网页代码,现在正则表达式不知道如何去写,去获取我想要的内容。
以下图片表格中为想要获取的内容。

URL为http://www.zjzwfw.gov.cn/zjzw/admins/article/articleshow.do?itemId=9630&mainCode=01178&deptId=001003002&category=其他行政权力
下面是后台代码
public void GetGeneralContent()
{
string strUrl = txtwz.Text.Trim();
WebRequest request = WebRequest.Create(strUrl);
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
//reader.ReadToEnd() 表示取得网页的源码
MatchCollection TitleMatchs = Regex.Matches(reader.ReadToEnd(), @"正则表达式", RegexOptions.IgnoreCase | RegexOptions.Multiline);

string mc = "";
foreach (Match NextMatch in TitleMatchs)
{
mc += NextMatch.Groups[1].Value;
}

//想获取名称(mc)、 类别、行政主体、行使层次、实施依据、备注的内容,获取成功后,insert到数据库中。
reader.Close();
reader.Dispose();
response.Close();

}

protected void btnSave_Click(object sender, EventArgs e)
{
GetGeneralContent();
}


刚学习.net,不知道写的对不对,说明白否,希望大家帮帮忙哈。
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
hbsyhx
.NET社区 62,275 成员 668,967 内容