.net HttpCrawler
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks; namespace HttpCrawler
{
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
var titles = from row in GetHtml("http://bbs.csdn.net/forums/DotNET/").DocumentNode.SelectSingleNode("//table[@class='table_list parent_forum ']").Elements("tr").Skip(1)
let td = row.Element("td")
where td != null
let a = td.Descendants("a").FirstOrDefault()
where a != null
select new
{
href = a.Attributes["href"].Value,
text = a.InnerText
};
var pages = from t in titles
.AsParallel().WithDegreeOfParallelism(20)
where t.href != null
let path = "http://bbs.csdn.net" + t.href
let subQuery = from nick in GetHtml(path).DocumentNode.SelectNodes("//span[@class='name2nick']")
where nick.InnerText == "sp1234"
select nick
where subQuery.Any()
select new
{
title = t.text,
href = path
};
var results = pages.ToList();
sw.Stop();
Console.WriteLine("不加并发的时间:"+sw.ElapsedMilliseconds);
Console.ReadKey();
}
static HtmlDocument GetHtml(string url)
{
var content = Encoding.UTF8.GetString(new WebClient().DownloadData(url));
var doc = new HtmlDocument();
doc.Load(new StringReader(content));
return doc;
}
}
}
.net HttpCrawler的更多相关文章
- Python分布式爬虫原理
转载 permike 原文 Python分布式爬虫原理 首先,我们先来看看,如果是人正常的行为,是如何获取网页内容的. (1)打开浏览器,输入URL,打开源网页 (2)选取我们想要的内容,包括标题,作 ...
- urllib2.URLError: <urlopen error [Errno 104] Connection reset by peer>
http://www.dianping.com/shop/8010173 File "综合商场1.py", line 152, in <module> httpC ...
- china-pub
#!/usr/bin/env python #coding:utf-8import urllib2,re,sys,os,types ...
- jd.py
#!/usr/bin/env python #coding:utf-8 import urllib2,re,sys,os,types #from bs4 import BeautifulSoup re ...
- 大数据抓取采集框架(摘抄至http://blog.jobbole.com/46673/)
摘抄至http://blog.jobbole.com/46673/ 随着BIG DATA大数据概念逐渐升温,如何搭建一个能够采集海量数据的架构体系摆在大家眼前.如何能够做到所见即所得的无阻拦式采集.如 ...
- shops
#!/usr/bin/env python #coding:utf- import urllib2,sys,re,os,string reload(sys); sys.setdefaultencodi ...
随机推荐
- P2151 [SDOI2009]HH去散步
题目描述 HH有个一成不变的习惯,喜欢饭后百步走.所谓百步走,就是散步,就是在一定的时间 内,走过一定的距离. 但是同时HH又是个喜欢变化的人,所以他不会立刻沿着刚刚走来的路走回. 又因为HH是个喜欢 ...
- NIO - 三大组件
NIO 概述 NIO有三个核心组件: 通道(Channels) 缓存(Buffers) 选择器(Selectors) 实际上,NIO的组件和类远不止这三个,但这个三个组件是核心.至于其它组件,例如Pi ...
- Leetcode模拟题篇
43. Multiply Strings 高精度非负整数的乘法. string multiply(string num1, string num2) { '); ; <= i; --i) { ; ...
- 【CF248E】Piglet's Birthday(动态规划)
[CF248E]Piglet's Birthday(动态规划) 题面 洛谷 CodeForces 翻译: 给定\(n\)个货架,初始时每个上面有\(a[i]\)个蜜罐. 有\(q\)次操作,每次操作形 ...
- WEB入门 四 CSS样式表深入
学习内容 Ø CSS选择器深入学习 Ø CSS继承 Ø CSS文本效果 Ø CSS图片效果 能力目标 Ø 掌握CSS选择器的组合声 ...
- MyBatis.2剖析
上次给大家介绍了一下properties 和 environments 的配置, 接下来就正式开始看源码了: 上次例子中,我们以 SqlSessionFactoryBuilder 去创建 SqlSes ...
- Gradle 命令之 --stacktrace , --info , --debug 用法
FAQ: Android studio 出现错误Run with --stacktrace option to get the stack trace. Run with --info or --de ...
- python学习笔记__反射
反射 # 通过字符串的形式对对象中的成员进行操作(获取/查找/添加/删除). 操作的内置函数: 1.获取 getattr(object, name) # 去对象object中获取name的内容 c ...
- NAT ------ 为什么手动设置NAT端口映射(转发)不成功,导致访问不了局域网服务器
手动设置端口映射成功的条件是路由器WAN口接的是外网IP,而不是网络提供商的路由器NAT之后的IP.假如有个外网的客户端,连的服务器IP一定要是外网IP(假设IP_A),如果自己的路由器WAN口接的是 ...
- ajax的坑
$('#mkcode').on('click',function(){ $.ajax({ type : 'POST', url : '__URL__/mkcode', data : {}, dataT ...