爬虫去重策略
- 将访问过的url保存到数据库中,效率较低
- 将访问过的url保存到set(内存)中,只需要o(1)的代价就可以查询url
对内存的占用较高 - url经过md5等方法哈希后保存到set中 (scrapy使用的)
- 用bitmap等方法,将访问过的url通过hash函数映射到某一位
申请一个8个位,每一个url映射到每一个位上
有冲突的可能性 哈希解决冲突的方法 - bloomfilter方法对bitmap进行改进,多重hash函数降低冲突
部分知识
Python用缩进表示代码块,不使用{}
Python 通常是一行写完一条语句,但如果语句很长,我们可以使用反斜杠()来实现多行语句,例如:
total = item_one + \
item_two + \
item_three
输入input()
输出print()
导入模块
在 python 用import
或者from...import
来导入相应的模块。
将整个模块(somemodule)导入,格式为:import somemodule
从某个模块中导入某个函数,格式为:from somemodule import somefunction
从某个模块中导入多个函数,格式为:from somemodule import firstfunc, secondfunc, thirdfunc
将某个模块中的全部函数导入,格式为:from somemodule import *
sys模块详解:https://www.cnblogs.com/Archie-s/p/6860301.html

网友评论