Reputation: 13
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.
Upvotes: 0
Views: 248
Reputation: 2364
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)
Upvotes: 1