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

本文探讨了网络爬虫设计中避免死循环的方法,提出了利用散列表存储已访问链接的解决方案,并介绍了链接去重和签名算法的重要性。

2014-04-24 21:52

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

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

代码:

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 }

 

转载于:https://www.cnblogs.com/zhuli19901106/p/3687445.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值