【发布时间】:2021-01-17 06:06:18
【问题描述】:
我正在尝试在 Python 中使用 BeautifulSoup 并行抓取网站。
我给函数一个 url 和一个深度变量,它看起来像这样:
def recursive_crawl(url, depth):
if depth == 0:
return
links = fetch_links(url) # where I use the requests library
print("Level : ", depth, url)
for link in links:
if is_link_valid(link) is True:
recursive_crawl( URL , depth - 1)
输出部分类似于:
Level : 4 site.com
Level : 3 site.com/
Level : 2 site.com/research/
Level : 1 site.com/blog/
Level : 1 site.com/stories/
Level : 1 site.com/list-100/
Level : 1 site.com/cdn-cgi/l/email-protection
等等。
我的问题是这样的:
我正在使用set(),以避免转到已经访问过的链接,因此我遇到了共享内存问题。我可以并行实现这个递归网络爬虫吗?
注意:请不要推荐scrapy,我希望使用BeautifulSoup之类的解析库来完成。
【问题讨论】:
标签: python recursion web-scraping parallel-processing web-crawler