首页 > 其他 > 详细

《Cracking the Coding Interview》——第10章:可扩展性和存储空间限制——题目5

时间:2014-04-25 02:51:09      阅读:505      评论:0      收藏:0      [点我收藏+]

2014-04-24 21:52

题目:如果你要设计一个网络爬虫,如何避免进入抓取死循环?

解法:对网址做格式归一化,重复检测。设计一个碰撞率尽量低的签名算法,对每次抓取了的网址计算签名并保存入库。一个正常网站中的超链接会有大量有向的环路(没有环路就代表你无法通过点击链接的方式回到之前访问过的地方,这肯定不科学啦),所以检测去重是必须的功能。

代码:

bubuko.com,布布扣
1 // 10.5 Assume that you‘re writing a web crawler, how would you avoid going into an infinite loop?
2 // Answer:
3 //    Every crawler starts from a seed link, and performs multithread BFS to go down the website and fetch webpages.
4 //    Every link visited will be put into a hash table. In case there is a loop, the link will be found in the hash table and will not be visited again.
5 int main()
6 {
7     return 0;
8 }
bubuko.com,布布扣

 

《Cracking the Coding Interview》——第10章:可扩展性和存储空间限制——题目5,布布扣,bubuko.com

《Cracking the Coding Interview》——第10章:可扩展性和存储空间限制——题目5

原文:http://www.cnblogs.com/zhuli19901106/p/3687445.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!