I have a long list of URL's that I need my Python script to iterate through. I need it to replace the parameter values in the URL with a certain string, and keep the parameter names the same.
But I have encounted a bit of a problem:
addr then contains something like this:
addr.query contains this:
I would like to replace all the parameter values ( in this case value1, value2 and value3) with a certain string, the same string for each of them.
The problem is urlparse squishes both the parameter names and thier values into the same element in a list, so its not so easy to automate replacing the parameter values with a string, while keeping the names the same. Anyone know how I can do this? I would appreciate any help on this, thank you.
But I have encounted a bit of a problem:
Code:
from urlparse import urlparse
urls = open("/path/to/urls.txt", "r").readlines()
for url in urls:
addr = urlparse(url)
Code:
ParseResult(scheme='http', netloc='www.example.com', path='/path/to/file.php', params='', query='param1=value1¶m2=value2&parm3=value3', fragment='')
Code:
param1=value1¶m2=value2&parm3=value3
The problem is urlparse squishes both the parameter names and thier values into the same element in a list, so its not so easy to automate replacing the parameter values with a string, while keeping the names the same. Anyone know how I can do this? I would appreciate any help on this, thank you.
Comment