I am working with a huge list of URL's. Just a quick question I have trying to slice a part of the URL out, see below:
http://www.domainname.com/page?CONTENT_ITEM_ID=1234¶m2¶m3
How could I slice out:
http://www.domainname.com/page?CONTENT_ITEM_ID=1234
Sometimes there is more than two parameters after the CONTENT_ITEM_ID and the ID is different each time, I am thinking it can be done by finding the first & and then slicing off the chars before that &, not quite sure how to do this tho.
Cheers
I figured it out below is what I needed to do:
This method isn't dependent on the position of the parameter within the url string. This could be refined, I'm sure, but it gets the point across.
Another option would be to use the split function, with & as a parameter. That way, you'd extract both the base url and both parameters.
returns a list with
beside urlparse there is also furl, which has IMHO better API.