[C#][固定格式网页解析]使用正则表达式处理网页的初步体会

news/2024/6/18 21:41:23
用IE WebControl解析网页得到特定网页中的特定数据:
    Set oDocument = Form2.m_IE.Document
    Set oelement = oDocument.Forms("searchdetail")
   
    Set oListTableElement = oelement.children(0).children(0)
这样的好处是简单,但坏处是:如何读取以及节点值究竟是什么含意这些信息,不太好抽取出来放到外面,作为灵活配置的文件。
因为它属于一个Childnodes一个Childnodes这么遍历的,无法灵活设定深度以及含义。
 
又体验了一把正则表达式,专门处理了特定站点HTML,由于我要处理的页面中总包含某些的固定代码。
 
发现下面的式子可以把一系列值解析到一个又一个的MatchCollection中。
我用的是"The Regulator"工具,试验结果如下:
 
也就是Collection“hiddentonenames”总是XX名的集合,按序排列;
Collection“hiddenspnames”总是XX名的集合,按序排列;
以此类推。
 
在C#中,可以用如下代码得到各个集合的值:
foreach(Match match in matchCollection)
{
    Group groupToneNames = match.Groups["hiddentonenames"];
    Group groupSpNames = match.Groups["hiddenspnames"];
    Group groupSingers = match.Groups["hiddensingers"];
}
 
这样,我可以针对这各种门派的Portal风格写出专门的正则表达式,但让他们输出的Collections名字都是一样的,从而让获取 一个铃声的各个字段的代码固定下来。
以后更新,只需要修改各个门派的正则表达式即可。
 
另外非常感谢王辉的《Web页面爬行实践》精彩文章!




http://www.niftyadmin.cn/n/3648849.html

相关文章

如何在Ubuntu 18.04上使用Apache设置密码身份验证[快速入门]

介绍 (Introduction) This tutorial will walk you through password-protecting assets on an Apache web server running on Ubuntu 18.04. Completing these steps will provide your server with additional security so that unauthorized users cannot access certain pa…

新闻组搜索技术讨论的利器

新闻组利器http://groups-beta.google.com/和http://www.google.com/advanced_group_search?hlzh-CN。尤其是前者,可以自定义自己喜欢的My Groups,My starred topics?,Recent groups,如果你有Google帐号或者Gmail帐号的话。

加载插件资源的Demo

首先了解一下Google加载资源源码 效果图 ImageView中加载src源码 final Drawable d a.getDrawable(R.styleable.ImageView_src); getDrawable源码 if (getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, value)) {if (value.type TypedValue.TYPE_ATTRIBUTE) {throw n…

Git使用教程详解之三 Git分支

Git 分支 几乎每一种版本控制系统都以某种形式支持分支。使用分支意味着你可以从开发主线上分离开来,然后在不影响主线的同时继续工作。在很多版本控制系统中,这是个昂贵的过程,常常需要创建一个源代码目录的完整副本,对大型项目来…

DigitalOcean电子书:面向全栈开发人员的Kubernetes

Download the Complete eBook!下载完整的电子书! Kubernetes for Full-Stack Developers eBook in EPUB format 适用于EPUB格式的 Full-Stack Developers电子书的Kubernetes Kubernetes for Full-Stack Developers eBook in PDF format Kubernetes适用于PDF格式的 …

换肤框架的搭建

首先所有皮肤的view——skinView:如ImageView public class SkinView {private View mSkView;//ImageViewprivate List<SkinAttr> mSkinAttrs;//src,backgroudpublic SkinView(View mSkView, List<SkinAttr> mSkinAttrs) {this.mSkView mSkView;this.mSkinAttrs …

javascript 符号_通过JavaScript了解Big O符号

javascript 符号If you’ve ever looked into getting a job as a developer you’ve probably come across this Google interview at some point and wondered ‘what the heck are they talking about?’. In this article, we’re going to explore what they mean throwi…

Windows系统一些计数器

Windows系统Windows -Processor指标名称指标描述指标范围指标单位CPU利用率&#xff08;% Processor Time&#xff09;% Processor Time指处理器执行非闲置线程时间的百分比。这个计数器设计成用来作为处理器活动的主要指示器。它通过在每个时间间隔中衡量处理器用于执行闲置处…