我正在制作一个简单的维基百科页面爬虫,并将详细信息写入运行 redis 的远程服务器。
1 The crawler asks the server for a page that needs crawling
2 The crawler loads the page and adds the pages that are found to an internal buffer
3 When the page has finished being parsed the results are sent to the server
我该如何执行以下操作:
保留在服务器上找到的所有页面,并使用一个标志来说明该页面是否已被抓取。
例如
- 1 http://en.wikipedia.org/wiki/MeBeam
- 0 http://en.wikipedia.org/wiki/Chemistry
- 1 http://en.wikipedia.org/wiki/Australia
我的问题是。
我如何要求redis给我它的第一个状态为0的链接(尚未爬行) 然后我如何告诉redis将该状态更改为1(在我抓取它之后)
最佳答案
您可以使用列表来保存要处理的页面
RPUSH mylist "http:// ...."
然后你可以使用 lpop 获取列表中的第一项
LPOP mylist
要跟踪已处理的页面,您可以使用一组
SADD myset "http://.....
最后收集地址是否在处理集中
SISMEMBER myset "http://...."
关于nosql - 将 redis nosql 与网络爬虫一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7673767/