本文整理匯總了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