python urlparse 모듈 의 실 용적 인 매 뉴 얼

1270 단어 urlparse 모듈
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urlparse
cve = 'CVE-2012-2143'
path = '/' + cve + '.html'

cveUrl = "http://cve.scap.org.cn/CVE-2015-2976.html"    #URL
parsedUrl = urlparse.urlparse(cveUrl)                   #   tuple  
print parsedUrl

urlList = list(parsedUrl)                               #     

urlList[2] = path                                       #    
tup = tuple(urlList)                                    #     
print urlList, tup

newUrl = urlparse.urlunparse(tup)                       #    URL
print parsedUrl.geturl(), newUrl                        #geturl    urlparse()   ,# urlunparse()         URL

C:\Python27\python.exe C:/Users/Administrator/PycharmProjects/excelTTT/TestUrllib.py
ParseResult(scheme='http', netloc='cve.scap.org.cn', path='/CVE-2015-2976.html', params='', query='', fragment='')
['http', 'cve.scap.org.cn', '/CVE-2012-2143.html', '', '', ''] ('http', 'cve.scap.org.cn', '/CVE-2012-2143.html', '', '', '')
http://cve.scap.org.cn/CVE-2015-2976.html http://cve.scap.org.cn/CVE-2012-2143.html

좋은 웹페이지 즐겨찾기