Removing a certain part of a string in python -
Removing a certain part of a string in python -
"submitted 1 year ago bagelpirate /r/books"
basically i'm learning web scraping , pulled info html of reddit page. need "bagelpirate" out of string. there way in python?
given starting string:
s = "submitted 1 year ago bagelpirate /r/books"
you (finding position of preceding , next substrings):
name = s[s.index(' ')+4:s.index(' /r/books')]
or utilize regular expression:
import re name = re.search(' (.+) /r/books', s).group(1)
that means, 'find "by (something) /r/books" in string , give me part indicated parentheses'.
it kind of depends format strings going in.
python
Comments
Post a Comment