我曾想过尝试编写一个简单的爬虫程序,它可以爬行并为我们的 NPO 网站和内容生成其发现结果列表。
有人对如何做到这一点有任何想法吗?您将爬虫指向何处开始?它如何发回其发现并仍然继续爬行?它如何知道它发现了什么等等。
可以肯定的是,你将重新发明轮子。但基础知识如下:
- 未访问过的 URL 列表 - 使用一个或多个起始页面作为种子
- 访问过的 URL 列表 - 这样您就不会兜圈子
- 一组针对您不感兴趣的 URL 的规则 - 这样您就不会为整个互联网建立索引
将它们放入持久存储中,以便您可以停止和启动爬虫而不会丢失状态。
算法是:
while(list of unvisited URLs is not empty) {
take URL from list
remove it from the unvisited list and add it to the visited list
fetch content
record whatever it is you want to about the content
if content is HTML {
parse out URLs from links
foreach URL {
if it matches your rules
and it's not already in either the visited or unvisited list
add it to the unvisited list
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)