在我的Django应用中,我需要从引荐来源网址中获取主机名request.META.get('HTTP_REFERER')
及其协议,以便从类似以下网址的网址中获取:
- https://docs.google.com/spreadsheet/ccc?key=blah-blah-blah-blah#gid=1
- /programming/1234567/blah-blah-blah-blah
- http://www.example.com
- https://www.other-domain.com/whatever/blah/blah/?v1=0&v2=blah+blah ...
我应该得到:
- https://docs.google.com/
- https://stackoverflow.com/
- http://www.example.com
- https://www.other-domain.com/
我查看了其他相关问题,并找到了有关urlparse的信息,但这并没有成功
>>> urlparse(request.META.get('HTTP_REFERER')).hostname
'docs.google.com'
/
http://www.domain.com