zoukankan
html css js c++ java
采集系统万能正则表达式
由于经常要写一些采集的程序,下面的三个函数是采集中的很常用的函数。姑且叫采集系统万能正则表达式吧。全部源码见
http://www.softbk.com/news.asp?id=3564
欢迎一起交流
//
获取页面的html源码
public
string
GetHtmlSource(
string
Url,
string
charset)
{
if
(charset
==
""
||
charset
==
null
) charset
=
"
gb2312
"
;
string
text1
=
""
;
try
{
HttpWebRequest request1
=
(HttpWebRequest)WebRequest.Create(Url);
HttpWebResponse response1
=
(HttpWebResponse)request1.GetResponse();
Stream stream1
=
response1.GetResponseStream();
StreamReader reader1
=
new
StreamReader(stream1, Encoding.GetEncoding(charset));
text1
=
reader1.ReadToEnd();
stream1.Close();
response1.Close();
}
catch
(Exception exception1)
{
}
return
text1;
}
public
string
SniffwebCode(
string
code,
string
wordsBegin,
string
wordsEnd)
{
string
NewsTitle
=
""
;
Regex regex1
=
new
Regex(
""
+
wordsBegin
+
@"
(?<title>[\s\S]+?)
"
+
wordsEnd
+
""
, RegexOptions.Compiled
|
RegexOptions.IgnoreCase);
for
(Match match1
=
regex1.Match(code); match1.Success; match1
=
match1.NextMatch())
{
NewsTitle
=
match1.Groups[
"
title
"
].ToString();
}
return
NewsTitle;
}
public
ArrayList SniffwebCodeReturnList(
string
code,
string
wordsBegin,
string
wordsEnd)
{
ArrayList urlList
=
new
ArrayList();
//
string NewsTitle = "";
Regex regex1
=
new
Regex(
""
+
wordsBegin
+
@"
(?<title>[\s\S]+?)
"
+
wordsEnd
+
""
, RegexOptions.Compiled
|
RegexOptions.IgnoreCase);
for
(Match match1
=
regex1.Match(code); match1.Success; match1
=
match1.NextMatch())
{
urlList.Add(match1.Groups[
"
title
"
].ToString());
}
return
urlList;
}
查看全文
相关阅读:
EntityFramework进阶(二)- DbContext预热
EntityFramework进阶(一)- DbContext与ObjectContext互转
ambari集成impala
搭建私有npm私库(使用verdaccio)
Vue中的slot,slot-scope,v-slot
Vue 中如何利用watch 监听对象中每一个属性的变化
css3的counter的用法
http请求整理
带有过渡效果的下拉列表,下拉的内容高度不一致且不确定如何办?
用js通过url传参把数据从一个页面传到另一个页面
原文地址:https://www.cnblogs.com/wuyisky/p/978258.html
最新文章
XML读取信息并显示
tomcat9.0配置跨域
tomcat之https配置(生成证书)
jq之导航菜单
文件加速之阿里云OSS(对象存储)
python的字符串
python常用算法
python中循环
python的运算符
python中的数据类型
热门文章
python数据类型和变量
JavaScript中逻辑运算符
Thinkphp5使用阿里大于短信验证
php中对象是引用类型吗?
Mybatis通用Join的实现
Elasticsearch自定义客户端(TransportClient)资源池
Vue.Js添加自定义插件
EntityFramework进阶(五)- 分页
EntityFramework进阶(四)- 实现批量新增
EntityFramework进阶(三)- 根据IQueryable获取DbContext
Copyright © 2011-2022 走看看