Quantcast
Channel: split multiple urls using urlparse in python - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by willeM_ Van Onsem for split multiple urls using urlparse in python

$
0
0

Based on your question, it looks like you have a list of URLs separated by new lines. In that case you can use a for loop to iterate over them:

list_pathlist = []for url in dat.split('\n'):    parsed = urlparse(url)    path = parsed[2] #defining after www.foo.com/    pathlist = path.split("/")    list_pathlist.append(pathlist)

In which case I suspect the result (list_pathlist) will be something like:

[['', '2016', '01', '0124'],['', '2016', '02', '1222'],...]

so a list of lists.

Or you can put it into a nice one-liner using list-comprehension:

list_pathlist = [urlparse(url)[2].split('/') for url in dat.split('\n')]

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>