Question: I am iterating over multiple URLs in a csv file; the URLs have the next structure:

```
http://www.parool.nl/parool/nl/4024/AMSTERDAM-CENTRUM/article/detail/3751723/2014/09/21
http://www.parool.nl/parool/nl/5/POLITIEK/article/detail/3751624/2014/09/20/VVD-wil-  boete-van-250-euro-voor-het-naroepen-van-vrouwen.dhtml

```

etc., 

I need to get the article category (after the 4th slash, "AMSTERDAM-CENTRUM" and "POLITIEK", in this case), and append them to a list.

I'm working with urllib2:

```
reader=CsvUnicodeReader(open("my.csv","r"))
for row in reader:
    url = row[0]
    req=urllib2.Request(url)

```

Is there a way to parse the URL?

Answer: 
If all URLs have similar structure you can simply use

```
url.rsplit('/')[6]

```
you can figure it out with [urlparse](https://docs.python.org/2/library/urlparse.html) module and get the article category with its `path` method then with `split('/')` function we splite the path with '\' and access 5th field with index [4] .

Demo :

```
>>> from urlparse import urlparse
>>> your_url=['http://www.parool.nl/parool/nl/4024/AMSTERDAM-CENTRUM/article/detail/3751723/2014/09/21','http://www.parool.nl/parool/nl/5/POLITIEK/article/detail/3751624/2014/09/20/VVD-wil-  boete-van-250-euro-voor-het-naroepen-van-vrouwen.dhtml']
>>> [urlparse(ul).path.split('/')[4] for ul in your_url]
['AMSTERDAM-CENTRUM', 'POLITIEK']

```