10/28
Part 3 of 6 · Clean linksLearn and do
Keep only the exact host
The third step keeps the crawl on one site.
from urllib.parse import urlparse
for link in ["http://example.com/x", "http://Example.com:80/x",
"http://news.example.com/n", "http://badexample.com/",
"mailto:me@example.com"]:
print(f"{link:27} {urlparse(link).hostname}")
print(urlparse("http://example.com:80/x").netloc)
What is urlparse("http://Example.com:80/x").hostname?
Pick one to see what it prints.
Pick an answer above to see the rest