#!/usr/bin/env python# -*- coding: utf-8 -*-import urlparsecve = ' cve-2012-2143 ' path = '/' + cve + '. html ' cveurl = ' http:// Cve.scap.org.cn/cve-2015-2976.html " #URLparsedUrl = urlparse.urlparse (Cveurl) #解构为tuple元组print parsedurlurllist = list (parsedurl) #元组转列表urlList [2] = path #修改列表tup = tuple (urllist) #列表转元组print Urllist, tupnewurl = urlparse.urlunparse (TUP) #元组重构URLprint Parsedurl.geturl (), newurl #geturl仅适用于urlparse () results, # urlunparse () You can refactor the normal list to a 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
This article is from the "Magicpwn" blog, make sure to keep this source http://magicpwn.blog.51cto.com/10497784/1678668
A practical manual for the Python urlparse module