from multiprocessingimport Pool
from country_url_getimport movie_page,get_movie_all_from,movie_get_all
#链接去重,断点重续
movie_url=[item['movie_page']for itemin movie_page.find()]#所有的应该爬取的url
db_urls = [item['url']for itemin movie_get_all.find()]#已爬取过的插入到数据库中的url
x =set(movie_url)
y =set(db_urls)#用set()c创建url集合
rest_of_urls = x-y#所有的应该爬取的url减去已经爬取过的url即是还没有爬取的url,再把这个参数代入到map函数中即可
if __name__=='__main__':
#创建多进程
pool= Pool()
pool.map(get_movie_all_from,rest_of_urls)#用map函数把url列表代入到函数get_movie_all中
pool.close()
pool.join()
网友评论