我必须创建自己的网络抓取工具(用于教育目的),抓取每个(或尽可能多的)保加利亚网站(.bg
域)并使用{{1返回正在运行的服务器Linux shell或curl -I
库中的命令。我正在使用一个类似数据库的大型网站,其中包含许多其他网站的链接,这是一个很好的起点。
所以我必须检查每个站点中的每个链接并检查它正在运行的服务器,将其推送到数据库中。棘手的是我需要打开每个链接并深入打开其他链接(如树)。所以我的想法是我必须使用BFS算法,将访问过的站点保留在列表中并添加我尚未访问过的每个链接。我也只对基本URL感兴趣,而不是网站内的相关网页,因为我对网站运行的服务器感兴趣。换句话说,我应该只检查requests
一次,我对example.bg
不感兴趣。
我真的不知道从哪里开始,所以我对使用example.bg/xyz/xyz/...
和Beautiful Soup
解决此问题的一般算法感兴趣。
答案 0 :(得分:0)
As you say you'll need to use a graph traversal algorithm as BFS or DFS, for that I would start by thinking a way to couple one of these algorithms for the purpose you want, that basically is mark each of the web sites as visited. I don't know if you are familiar to it. I can give you a link for reference: http://www.geeksforgeeks.org/depth-first-traversal-for-a-graph/
Secondly you can start using Beautiful Soup and implement a way to pull data of interest out of the HTML files.