473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Python urlparse how to edit parameter values?

2
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:

Expand|Select|Wrap|Line Numbers
  1. from urlparse import urlparse
  2. urls = open("/path/to/urls.txt", "r").readlines()
  3. for url in urls:
  4.     addr = urlparse(url)
  5.  
addr then contains something like this:

Expand|Select|Wrap|Line Numbers
  1. ParseResult(scheme='http', netloc='www.example.com', path='/path/to/file.php', params='', query='param1=value1&param2=value2&parm3=value3', fragment='')
  2.  
addr.query contains this:
Expand|Select|Wrap|Line Numbers
  1. param1=value1&param2=value2&parm3=value3
  2.  
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.
Oct 28 '11 #1
3 6186
bvdet
2,851 Expert Mod 2GB
Could you provide a sample of the URLs you are trying to parse and what the modified URLs are supposed to look like?
Oct 28 '11 #2
dwblas
626 Expert 512MB
You may be able to split on the "&, change the string, and "&".join() etc.
Oct 30 '11 #3
Glenton
391 Expert 256MB
Regular expressions would be a good way to do it.
Oct 31 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Marcin | last post by:
Hello! Is there any method to detect parameters values passed to called method? For example: public Guid ApplicationLogin(string userName, string password, int dbId)
2
by: The Plankmeister | last post by:
Hi... I have a query which I'm accessing through PHP as a stored procedure. However, I need to be able not to pass a couple of parameters in certain situations. When I do this, I get an error: ...
1
by: Hardy Wang | last post by:
Hi all: I have a logging class, which is used to log errors automatically. With StackFrame.GetMethod().GetParameters() function, I am able to read all parameter information except the real...
2
by: Steve Amey | last post by:
Hi all I would like to get the values of Parameters passed to a method from a centralized exception handling routine. At the moment, the exception is passed to the handler, and I can get the...
2
by: Miguel | last post by:
I have followed the advice noted throughout this group for capturing parameter values in a report header. It works, but the parameter dialog box appears twice,once for the query and once for the...
2
by: news.microsoft.com | last post by:
Hi all. If I wanted to write something so that, when an exception was thrown, and the stack unwound, the stack trace was captured with the values of the parameters (instead of just the parameter...
2
by: chris | last post by:
I am sure I am overlooking something simple, but here goes. In the global.asax file I have some code in the Application_Error method that reads information out of the current exception and emails...
8
by: John Salerno | last post by:
I figured my first step is to install the win32 extension, which I did, but I can't seem to find any documentation for it. A couple of the links on Mark Hammond's site don't seem to work. ...
6
by: MLH | last post by:
I have a query (SQL below) that operates on values entered by users into an unbound form to append a record to tblAdmin. I do not under- stand the basis for the error. There are some 17 or so data...
2
by: ME | last post by:
How would one obtain the parameter VALUES of a method that has already run? I can find the method using the StackTrace and StackFrame classes but once I find the method I would like to obtain the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.