referenced_links = ['your_initial_page.html']
while referenced_links: # if the array isn't empty...
crawl_dom(referenced_links[0])
referenced_links.pop(0) # remove the first item in that array
def crawl_dom(url):
# download the url, parse the DOM and append all hyperlinks to the array referenced_links
1 回答
解析该单个页面的DOM时,将所有链接(在同一个域中)存储在一个数组中 . 然后,在解析结束时,检查数组是否为空 . 如果不是,请取第一个链接并执行相同操作 .
就像这样(代码示例使用类似Python的语法编写,但您可以轻松地将其调整为PHP - 我的生锈) .