Created
December 31, 2018 23:12
-
-
Save kanrourou/881c9eb7255d6af8061d0b88f9ea6e48 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
def get_all_links(page): | |
#extract all links from the html page | |
def get_page(link): | |
#get the html page | |
def addTasks(tasks, newTasks): | |
for task in newTasks: | |
tasks.append(task) | |
def crawl(seed) | |
{ | |
tasks = [seed] | |
visited = [] | |
while(tasks): | |
link = tasks.pop(); | |
if link not in visited: | |
page = get_page(link) | |
links = get_all_links(page) | |
addTasks(tasks, links) | |
visited.append(link) | |
#do something with the page... | |
#maybe store in DB | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment