Exemplo n.º 1
0
    def parse_url(
        self,
        extract: Literal["PROTOCOL", "HOST", "PATH", "REF", "AUTHORITY",
                         "FILE", "USERINFO", "QUERY", ],
        key: str | None = None,
    ) -> StringValue:
        """Parse a URL and extract its components.

        `key` can be used to extract query values when `extract == 'QUERY'`

        Parameters
        ----------
        extract
            Component of URL to extract
        key
            Query component to extract

        Examples
        --------
        >>> url = "https://www.youtube.com/watch?v=kEuEcWfewf8&t=10"
        >>> parse_url(url, 'QUERY', 'v')  # doctest: +SKIP
        'kEuEcWfewf8'

        Returns
        -------
        StringValue
            Extracted string value
        """
        import ibis.expr.operations as ops

        return ops.ParseURL(self, extract, key).to_expr()
Exemplo n.º 2
0
def parse_url(arg, extract, key=None):
    """
    Returns the portion of a URL corresponding to a part specified
    by 'extract'
    Can optionally specify a key to retrieve an associated value
    if extract parameter is 'QUERY'

    Parameters
    ----------
    extract : one of {'PROTOCOL', 'HOST', 'PATH', 'REF',
                'AUTHORITY', 'FILE', 'USERINFO', 'QUERY'}
    key : string (optional)

    Examples
    --------
    parse_url("https://www.youtube.com/watch?v=kEuEcWfewf8&t=10", 'QUERY', 'v')
    yields 'kEuEcWfewf8'

    Returns
    -------
    extracted : string
    """
    return _ops.ParseURL(arg, extract, key).to_expr()