I have a URL:
/c/s/www.local.com/pure/123/india/news/hunt-still-on-for-biker-who-gunned-down-man
I want to extract the string starting from /pure:
/pure/123/india/news/hunt-still-on-for-biker-who-gunned-down-man
What is the best way to do it in python.
Use index()
and the []
notation.
str = "/c/s/www.local.com/pure/123/india/news/hunt-still-on-for-biker-who-gunned-down-man"
print(str[str.index("/pure"):])
str[index:]
means grab all chars from str
starting at index
till the end of the string.
这就是你要找的:
url[url.index('/pure'):]
If the number of characters is always the same from the beginning of the string you can just dismiss the first characters. ex. a_string = "/c/s/www.local.com/pure/123/india/news/hunt-still-on-for-biker-who-gunned-down-man"
print (a_string[24:])
Then you can consider regular expressions, as well as other methods.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.