提取URL中的内容

from urllib.parse import urlparse


a = urlparse('https://www.jb51.net/article/139594.htm')
print(dir(a))
print(a.netloc)
print(a.path)
print(a.scheme)

['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '_asdict', '_encoded_counterpart', '_fields', '_hostinfo', '_make', '_replace', '_source', '_userinfo', 'count', 'encode', 'fragment', 'geturl', 'hostname', 'index', 'netloc', 'params', 'password', 'path', 'port', 'query', 'scheme', 'username']
www.jb51.net
/article/139594.htm
https

说明: 若想知道一个变量的属性  可以用dir()函数. 查看

猜你喜欢

转载自blog.csdn.net/weixin_42785547/article/details/86360508