#!/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
时间: 2024-10-07 12:35:37