本文整理汇总了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)
示例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)
示例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
示例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
示例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
示例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
示例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)
示例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