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;
}
查看全文
相关阅读:
编写一个C语言程序,产生一个存放26个英文字母组成的线性链表(a,b,c,…,z),并输出该线性表。
JavaScript之数组函数
JavaScript之数据类型转化
xml约束
PHP初认识
JavaScript与css3
JavaScript与css
HTML5与JavaScript
JSON
xml初认识
原文地址:https://www.cnblogs.com/wuyisky/p/978258.html
最新文章
函数节流
javascript-call、apply、bind区别
Sublime下运行javascript
Laya-浏览器复制文本到剪贴板
C# 队列(Queue)
C# 栈(Stack)
C#-类型和变量
为什么我也打算学C#了
Laya3D场景
Laya3D资源加载
热门文章
开始写博客,记录自己学习的东西
有效的括号
删除链表的倒数第N个节点
电话号码的字母组合
三数之和
盛最多的水的容器
最长回文子串
给像素很低的图像扣章
罗马转数字
将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 
Copyright © 2011-2022 走看看