文章采集

「已注销」 2010-09-04 04:35:37
思路是怎么样的!?
...全文
505 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-09-04
  • 打赏
  • 举报
回复
string pattern = @"(?is)<div\s+class=\"title\">(.*?)</div>";
whb147 2010-09-04
  • 打赏
  • 举报
回复
看一下小偷程序即可
「已注销」 2010-09-04
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 adengliuqing 的回复:]
(?is)<div class="title"><h1>.+?</h1></div>
[/Quote]
可以给点完整的代码吗?
米娜Rose 2010-09-04
  • 打赏
  • 举报
回复
(?is)<div class="title"><h1>.+?</h1></div>
米娜Rose 2010-09-04
  • 打赏
  • 举报
回复

/// <summary>
/// 返回超连接的数组
/// </summary>
/// <param name="userInput"></param>
/// <param name="WebText"></param>
/// <returns></returns>
public string[] Get_url_Array(string userInput, string WebText)
{
MatchCollection mc = Regex.Matches(userInput, WebText);
ArrayList Url_List = new ArrayList();
foreach (Match m in mc)
{
Url_List.Add(m.Value.ToString().Replace(" ", " "));
}
return (string[])Url_List.ToArray(typeof(string));
}
「已注销」 2010-09-04
  • 打赏
  • 举报
回复
怎么取得<div class="title"><h1></h1></div>之内的内容,正则表达式怎么写?
「已注销」 2010-09-04
  • 打赏
  • 举报
回复
Get_url_Array方法怎么没有啊 ?
米娜Rose 2010-09-04
  • 打赏
  • 举报
回复

/// <summary>
/// 获取网页源代码
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public string GetHtmlEx(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Timeout = 60000;
request.UserAgent = userAgent;
request.ContentType = contentType;
request.CookieContainer = cookie;
request.Accept = accept;
request.Method = "get";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.ContentType.Length == 9)
{
_encode = "gbk";
}
else
{
_encode = getEncoding(response);
}
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding(_encode));
String html = reader.ReadToEnd();
response.Close();
return html;
}

string Htmlstring = GetHtmlEx(url);
Htmlstring = Regex.Replace(Htmlstring, "\"", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, "'", "", RegexOptions.IgnoreCase);
string[] arr0 = Get_url_Array(Htmlstring, rulesObj.RRegex_0);//标题


「已注销」 2010-09-04
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wuyq11 的回复:]
抓取页面,定时
string param = "";
byte[] bs = Encoding.ASCII.GetBytes(param);
HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create( "" );
req.Method = "POST";
req.ContentType = "applicatio……
[/Quote]
我现在是能过滤指定标签,不知道是怎么取指定标签内的内容,给点实例!
wuyq11 2010-09-04
  • 打赏
  • 举报
回复
如Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)(?<url>[^'""\s>]+)\1[^>]*>(?<text>(?:(?!</?a\b).)*)</a>");
MatchCollection mc = reg.Matches("");
foreach (Match m in mc)
{
Console.Write(m.Groups["url"].Value);
}
wuyq11 2010-09-04
  • 打赏
  • 举报
回复
正则获取特定数据
wuyq11 2010-09-04
  • 打赏
  • 举报
回复
抓取页面,定时
string param = "";
byte[] bs = Encoding.ASCII.GetBytes(param);
HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create( "" );
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = bs.Length;
webclient等
米娜Rose 2010-09-04
  • 打赏
  • 举报
回复
用正则过滤
「已注销」 2010-09-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 adengliuqing 的回复:]
使用HttpWebRequest对象给要采集的页面发送一个请求,然后可以得到源码,自己想取什么就取什么。
[/Quote]
取指定标签内的内容怎么做?
米娜Rose 2010-09-04
  • 打赏
  • 举报
回复
使用HttpWebRequest对象给要采集的页面发送一个请求,然后可以得到源码,自己想取什么就取什么。
孟子E章 2010-09-04
  • 打赏
  • 举报
回复
就是去代码请求一个url,然后分析源代码,提取自己感兴趣的,。网上很多代码的

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧