Skip to content

EltonChou/no-more-query-string

Repository files navigation

PyPI GitHub Workflow Status (branch) PyPI - Downloads PyPI - Python Version PyPI - License

no-more-query-string

Remove unneccessary query-string from the URL given. Especially fbclid.

Changelog

Installation

pip install no-more-query-string

Usage

from no_more_qs import NoMoreQS

nmq = NoMoreQS()
url = "https://www.youtube.com/watch?v=h-RHH79hzHI&feature=emb_logo&ab_channel=Ceia"

nmq.clean(url)
# 'https://www.youtube.com/watch?v=h-RHH79hzHI'

or you just want to remove fbclid

url = "https://www.youtube.com/watch?v=h-RHH79hzHI&feature=emb_logo&ab_channel=Ceia&fbclid=IwAR2NasdasdasdadasdfP58isTW-c3U"

NoMoreQs.remove_fbclid(url)
# 'https://www.youtube.com/watch?v=h-RHH79hzHI&feature=emb_logo&ab_channel=Ceia'

Parameters

fbclid will be cleaned from all domains

# default
NoMoreQS(include_flds=[], exclude_flds=[], strict=True)

include_flds ( List[str] | Tuple[str]=[] )

first-level domains list which are allowed to clean query string.

include_flds = ('youtube.com', 'google.com')

url = "https://www.youtube.com/watch?v=h-RHH79hzHI&feature=emb_logo&ab_channel=Ceia&fbclid=IwAR2NasdasdasdadasdfP58isTW-c3U"

NoMoreQS(include_flds=include_flds).clean(url)
# 'https://www.youtube.com/watch?v=h-RHH79hzHI'

exclude_flds ( List[str] | Tuple[str]=[] )

first-level domains which are disallowed to clean query string.

exclude_flds = ('youtube.com', 'google.com')

url = "https://www.youtube.com/watch?v=h-RHH79hzHI&feature=emb_logo&ab_channel=Ceia&fbclid=IwAR2NasdasdasdadasdfP58isTW-c3U"

NoMoreQS(exclude_flds=exclude_flds).clean(url)
# 'https://www.youtube.com/watch?v=h-RHH79hzHI&feature=emb_logo&ab_channel=Ceia'

strict ( bool=True )

if the domain is not in include_flds or exclude_flds

  • True(default): Remove all unneccessary query string.
  • False: Only remove fbclid from query string.
url = "https://www.youtube.com/watch?v=h-RHH79hzHI&feature=emb_logo&ab_channel=Ceia&fbclid=IwAR2NasdasdasdadasdfP58isTW-c3U"

NoMoreQS(strict=True).clean(url)
# 'https://www.youtube.com/watch?v=h-RHH79hzHI'

NoMoreQS(strict=False).clean(url)
# 'https://www.youtube.com/watch?v=h-RHH79hzHI&feature=emb_logo&ab_channel=Ceia'