Python extrahiert den Domänennamen aus der URL
为情所困
为情所困 2017-06-28 09:22:24
0
2
757

Wie extrahiert Python den Domainnamen aus der URL? URLs gibt es in verschiedenen Formaten wie folgt:

Geben Sie ein:

https://docs.google.com/spreadsheet/ccc?key=blah-blah-blah-blah#gid=1
https://stackoverflow.com/questions/1234567/blah-blah-blah-blah
http://www.domain.com
https://www.other-domain.com/whatever/blah/blah/?v1=0&v2=blah+blah ...

Ausgabe:

docs.google.com
stackoverflow.com
www.domain.com
www.other-domain.com
为情所困
为情所困

Antworte allen(2)
仅有的幸福

使用Python 内置的模块 urlparse

from urlparse import *
url = 'https://docs.google.com/spreadsheet/ccc?key=blah-blah-blah-blah#gid=1'
result = urlparse(url)

result 包含了URL的所有信息

ringa_lee

原文出处:Python实用脚本清单

从URL中提取域名

def extractDomainFromURL(url):
    """Get domain name from url"""
    from urlparse import urlparse
    parsed_uri = urlparse(url)
    domain = '{uri.netloc}'.format(uri=parsed_uri)
    return domain
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!