本文整理汇总了Python中urlparse.urldefrag方法的典型用法代码示例。如果您正苦于以下问题:Python urlparse.urldefrag方法的具体用法?Python urlparse.urldefrag怎么用?Python urlparse.urldefrag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urlparse
的用法示例。
在下文中一共展示了urlparse.urldefrag方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_fragment
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urldefrag [as 别名]
def remove_fragment(url):
pure_url, frag = urldefrag(url)
return pure_url
示例2: remove_fragment
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urldefrag [as 别名]
def remove_fragment(self, url):
pure_url, frag = urldefrag(url)
return pure_url
# 使用HTMLParser分析html,获取到里面的urls,也可以使用BeautifulSoup等.
示例3: test_urldefrag
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urldefrag [as 别名]
def test_urldefrag(self):
for url, defrag, frag in [
('http://python.org#frag', 'http://python.org', 'frag'),
('http://python.org', 'http://python.org', ''),
('http://python.org/#frag', 'http://python.org/', 'frag'),
('http://python.org/', 'http://python.org/', ''),
('http://python.org/?q#frag', 'http://python.org/?q', 'frag'),
('http://python.org/?q', 'http://python.org/?q', ''),
('http://python.org/p#frag', 'http://python.org/p', 'frag'),
('http://python.org/p?q', 'http://python.org/p?q', ''),
(RFC1808_BASE, 'http://a/b/c/d;p?q', 'f'),
(RFC2396_BASE, 'http://a/b/c/d;p?q', ''),
]:
self.assertEqual(urlparse.urldefrag(url), (defrag, frag))
示例4: _urljoin
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urldefrag [as 别名]
def _urljoin(base, url):
"""
Construct a full ("absolute") URL by combining a "base URL" with another
URL. Informally, this uses components of the base URL, in particular the
addressing scheme, the network location and (part of) the path, to provide
missing components in the relative URL.
Additionally, the fragment identifier is preserved according to the HTTP
1.1 bis draft.
@type base: C{bytes}
@param base: Base URL.
@type url: C{bytes}
@param url: URL to combine with C{base}.
@return: An absolute URL resulting from the combination of C{base} and
C{url}.
@see: L{urlparse.urljoin}
@see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-22#section-7.1.2}
"""
base, baseFrag = urldefrag(base)
url, urlFrag = urldefrag(urljoin(base, url))
return urljoin(url, b'#' + (urlFrag or baseFrag))
示例5: _url_path_only
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urldefrag [as 别名]
def _url_path_only(self, url):
return urldefrag(url)[0]
示例6: get_tag_a
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urldefrag [as 别名]
def get_tag_a(self):
# 处理A链接
for tag in self.soup.find_all('a'):
if tag.attrs.has_key('href'):
link = tag.attrs['href']
# link = urlparse.urldefrag(tag.attrs['href'])[0] # 处理掉#tag标签信息
complet_link = self.complet_url(link.strip())
if complet_link:
self.url_links['a'].append(complet_link)
return self.url_links