0

I would like to look get the host name using requests repository in python. I tried to do this like that:

pprint(requests.get("https://www.facebook.com/").headers['domain'])

but it doesn't work. If it is possible in other repository I would be grateful for any answer.

1

1 Answer 1

1

Based on Regular Expression - Extract subdomain & domain

import requests
import re

p = re.compile("^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/?\n]+)")

r = requests.get("https://www.google.com/")
domain = p.match(r.url).group(1)
print(domain)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.