Regular Expressions in Python
Hi,
I am looking to split a complete URL like www.google.com/index.html into main URL www.google.com and remaining url /index.html. How can I do this in python ? Thanks |
Code:
import urlparse |
I was just playing with it a little, it seems to split some urls strangly
Code:
>>> urlparse.urlparse('http://www.linuxquestions.org/questions/showthread.php?s=&threadid=363336') |
How is this urlparse works ? I mean if I put www.google.com/index.html than it gives some blank values.
|
This function seems a little cleaner, it just sptilts the url into two parts as you need
Code:
def parse_url(url): |
Quote:
|
Thanks shanein, it is working :)
anyway another thing which I am not able to do is to get the file name. Like if given a URL www.google.com/docs/index.html so I want to break it in www.google.com/docs/ and index.html. I am not able to think, how to use delimiters to get the file name :) |
I am not sure I am fully following you, but you could use the split method again like this, but choose '/' as the dilimeter
Code:
>>> "http://www.google.com/docs/index.html".split('/') Code:
url = "http://www.google.com/docs/index.html" Code:
def url_file(url): |
All times are GMT -5. The time now is 07:28 PM. |