Memoize2

Python URL をパース


>>> from urllib.parse import urlparse

>>> url = "http://basicwerl.com/funny-face.jpg?size=27000x3"
>>> u = urlparse(url)
>>> u
ParseResult(scheme='http', netloc='basicwerl.com', path='/funny-face.jpg', params='', query='size=27000x3', fragment='')

>>> url = "../img/funny-face.jpg"
>>> u = urlparse(url)
>>> u
ParseResult(scheme='', netloc='', path='../img/funny-face.jpg', params='', query='', fragment='')

>>> url = "http://basicwerk.com/memoize2/#python.BeautifulSoup.modify_attrs.txt"
>>> u = urlparse(url)
>>> u
ParseResult(scheme='http', netloc='basicwerk.com', path='/memoize2/', params='', query='', fragment='python.BeautifulSoup.modify_attrs.txt')
>>> u.netloc
'basicwerk.com'

参考: Python 3.5.2 21.8. urllib.parse — URL を解析して構成要素にする

 

Last modified: 2016-10-05

Page Top

Index

Bw

Author: 中村 心 Shin Nakamura, Email: sn(at)i.basicwerk.com


© Shin Nakamura/BasicWerk 2008 - 2017