當前位置: 首頁>>代碼示例>>Python>>正文


Python parse.urljoin方法代碼示例

本文整理匯總了Python中future.moves.urllib.parse.urljoin方法的典型用法代碼示例。如果您正苦於以下問題:Python parse.urljoin方法的具體用法?Python parse.urljoin怎麽用?Python parse.urljoin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在future.moves.urllib.parse的用法示例。


在下文中一共展示了parse.urljoin方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: request

# 需要導入模塊: from future.moves.urllib import parse [as 別名]
# 或者: from future.moves.urllib.parse import urljoin [as 別名]
def request(self, endpoint, method='get', **kwargs):
        """
        Request data from a nominated endpoint.

        Args:
            endpoint (str): The endpoint from which to receive data.
            method (str): The method to use when requestion this resource.
            **kwargs (dict): Additional arguments to pass through to
                `requests.request`.

        Returns:
            requests.Response: The response object associated with this request.
        """
        import requests
        url = urljoin(self.base_url, endpoint)
        return requests.request(method, url, **kwargs) 
開發者ID:airbnb,項目名稱:omniduct,代碼行數:18,代碼來源:base.py

示例2: request

# 需要導入模塊: from future.moves.urllib import parse [as 別名]
# 或者: from future.moves.urllib.parse import urljoin [as 別名]
def request(self, method, url, data=None, headers=None, **kwargs):
        full_url = urljoin(self.host, url)

        if not headers:
            headers = {}

        headers['user-agent'] = self.__user_agent()

        try:
            rsp = self.__do_request(data, full_url, headers, kwargs, method)
        except TokenExpiredError:
            if self.refresher:
                self.refresher.refresh(self)
                rsp = self.__do_request(data, full_url, headers, kwargs, method)
            else:
                raise

        if rsp.ok:
            return rsp
        else:
            raise MendeleyApiException(rsp) 
開發者ID:Mendeley,項目名稱:mendeley-python-sdk,代碼行數:23,代碼來源:session.py

示例3: add_src

# 需要導入模塊: from future.moves.urllib import parse [as 別名]
# 或者: from future.moves.urllib.parse import urljoin [as 別名]
def add_src(html_body, base=''):
    """
    添加圖片文件鏈接(1、添加真實鏈接;2、替換本地鏈接)
    :param html_body:
    :param base:
    :return:
    """
    rule = r'data-src="(.*?)"'
    img_data_src_list = re.compile(rule, re.I).findall(html_body)
    for img_src in img_data_src_list:
        # 處理相對鏈接
        if base:
            new_img_src = urljoin(base, img_src)
        if new_img_src.startswith('/'):
            continue
        # 遠程轉本地
        local_img_src = remote_to_local(new_img_src)
        img_dict = {
            'img_src': img_src,
            'local_img_src': local_img_src
        }
        html_body = html_body.replace(img_src, '%(img_src)s" src="%(local_img_src)s' % img_dict)
    return html_body 
開發者ID:zhanghe06,項目名稱:news_spider,代碼行數:25,代碼來源:img_remote_to_local_fs.py

示例4: base_url

# 需要導入模塊: from future.moves.urllib import parse [as 別名]
# 或者: from future.moves.urllib.parse import urljoin [as 別名]
def base_url(self):
        """str: The base url of the REST API."""
        url = urljoin('{}://{}:{}'.format(self.server_protocol, self.host, self.port or 80), self.endpoint_prefix)
        if not url.endswith('/'):
            url += '/'
        return url 
開發者ID:airbnb,項目名稱:omniduct,代碼行數:8,代碼來源:base.py

示例5: replace_src

# 需要導入模塊: from future.moves.urllib import parse [as 別名]
# 或者: from future.moves.urllib.parse import urljoin [as 別名]
def replace_src(html_body, base=''):
    """
    替換圖片文件鏈接(替換本地鏈接)
    :param html_body:
    :param base:
    :return:
    """
    rule = r'src="(.*?)"'
    img_data_src_list = re.compile(rule, re.I).findall(html_body)
    for img_src in img_data_src_list:
        # 處理//,補充協議
        if img_src.startswith('//'):
            img_src = 'http:%s' % img_src
        # 處理相對鏈接
        if base:
            new_img_src = urljoin(base, img_src)
        if new_img_src.startswith('/'):
            continue
        # 遠程轉本地
        local_img_src = remote_to_local(new_img_src)
        img_dict = {
            'img_src': img_src,
            'local_img_src': local_img_src
        }
        html_body = html_body.replace(img_src, '%(local_img_src)s" data-src="%(img_src)s' % img_dict)
    return html_body 
開發者ID:zhanghe06,項目名稱:news_spider,代碼行數:28,代碼來源:img_remote_to_local_fs.py

示例6: parse_js_msg_list

# 需要導入模塊: from future.moves.urllib import parse [as 別名]
# 或者: from future.moves.urllib.parse import urljoin [as 別名]
def parse_js_msg_list(self):
        msg_list = self.ctx.call('r_msg_list')
        app_msg_ext_info_list = [i['app_msg_ext_info'] for i in msg_list]
        comm_msg_info_date_time_list = [time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(i['comm_msg_info']['datetime'])) for i in msg_list]
        # msg_id_list = [i['comm_msg_info']['id'] for i in msg_list]
        msg_data_list = [
            {
                # 'article_id': '%s_000' % msg_id_list[index],
                'article_id': get_finger(i['title']),
                'article_url': urljoin('https://mp.weixin.qq.com', un_escape(i['content_url'])),
                'article_title': i['title'],
                'article_abstract': i['digest'],
                'article_pub_time': comm_msg_info_date_time_list[index],
            } for index, i in enumerate(app_msg_ext_info_list)
        ]
        msg_ext_list = [i['multi_app_msg_item_list'] for i in app_msg_ext_info_list]
        for index_j, j in enumerate(msg_ext_list):
            for index_i, i in enumerate(j):
                msg_data_list.append(
                    {
                        # 'article_id': '%s_%03d' % (msg_id_list[index_j], index_i + 1),
                        'article_id': get_finger(i['title']),
                        'article_url': urljoin('https://mp.weixin.qq.com', un_escape(i['content_url'])),
                        'article_title': i['title'],
                        'article_abstract': i['digest'],
                        'article_pub_time': comm_msg_info_date_time_list[index_j],
                    }
                )
        return msg_data_list 
開發者ID:zhanghe06,項目名稱:news_spider,代碼行數:31,代碼來源:weixin.py

示例7: trigger_dag

# 需要導入模塊: from future.moves.urllib import parse [as 別名]
# 或者: from future.moves.urllib.parse import urljoin [as 別名]
def trigger_dag(dag_id, run_id, api_url, conf, alg):
    json_data = {
        "run_id": run_id,
        "conf": conf
    }
    json_data["token"] = jwt.encode(json_data, private_key, algorithm=alg).decode("utf-8")
    return requests.post(url=urljoin(api_url, f"""/api/experimental/dags/{dag_id}/dag_runs"""),
                         json=json_data) 
開發者ID:Barski-lab,項目名稱:cwl-airflow,代碼行數:10,代碼來源:trigger.py

示例8: make_request

# 需要導入模塊: from future.moves.urllib import parse [as 別名]
# 或者: from future.moves.urllib.parse import urljoin [as 別名]
def make_request(self,
                     uri=None,
                     headers=None,
                     data=None,
                     request_type='GET',
                     output_format='raw',
                     return_type=False,
                     no_token=False,
                     timeout=None,
                     callback=None,
                     **request_kwargs):
        """
        Handle the HTTP requests.

        Output: list
        """

        self.uri = str(uri)
        self.data = data
        self.request_type = request_type.upper()
        self.output_format = output_format.lower()
        self.return_type = return_type
        self.callback = callback
        self.timeout = timeout or self.timeout
        self.request_kwargs = request_kwargs

        if self.request_type not in self.valid_request_types:
            logger.debug("HTTP request made but unsupported request type given.")
            return None

        if uri:
            request_urls = [urljoin(str(url), self.uri) for url in self.urls]

            if no_token:
                self.headers.pop('X-Plex-Token', None)
            if headers:
                self.headers.update(headers)

            responses = []
            for r in self._http_requests_pool(request_urls):
                responses.append(r)

            return responses[0]

        else:
            logger.debug("HTTP request made but no enpoint given.")
            return None 
開發者ID:Tautulli,項目名稱:Tautulli,代碼行數:49,代碼來源:http_handler.py


注:本文中的future.moves.urllib.parse.urljoin方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。