Skip to content

Changed the hardcoded part and added Docstring #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions scripts/09_basic_link_web_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,36 @@


def crawl(url):

"""
Crawls a page
Arguments:
- URL of the page to crawl
Return:
- List of all unique links found
"""

found_link = []
req = requests.get(url)

# Check if successful
if(req.status_code != 200):
return []

# Find links
links = link_re.findall(req.text)
# Finding unique links
links = set(link_re.findall(req.text))

print("\nFound {} links".format(len(links)))
print("\nFound {} unique links".format(len(links)))

# Search links for emails
for link in links:

# Get an absolute URL for a link
link = urljoin(url, link)

found_link.append(link)
print(link)

return found_link

if __name__ == '__main__':
crawl('http://www.realpython.com')
url = input("Enter a url to crawl: ")
crawl(url)