Reputation:
today i want to use a YouTube-RSS Feed for notify me about new videos. So all is working now, but i want to get a specific string and want to remove all Textparts that are coming after, and before my specific string. So, how can I do that? I think i can use .partition and .split but doesn't know how exactly i can use that with my problem.
So, the XML Description has this content:
Quellen: https://sites.google.com/view/sources...
Das Leben zu begreifen ist ziemlich schwierig, weil du immer mittendrin steckst. Es ist, als wolltest du herausfinden wie groß der Ozean ist, während du darin schwimmst. Meistens bist du damit beschäftigt, dich über Wasser zu halten. Es ist also gar nicht so einfach, herauszufinden, was du mit deinem Leben machen und wie du deine Zeit einsetzen willst.
Soundcloud: http://bitlylink
Facebook: http://bitlylink
Twitter: http://bitlylink
Instagram: http://bitlylink
I want to remove the first line with "QUELLEN: ..." and the social media links from the bottom of the description. I only want the long line as string.
Important to know, the "QUELLEN" URL does change itself with every video. But it's always the same site: https://sites.google.com
.
So, how can i remove all parts except the long line from the description?
Upvotes: 0
Views: 55
Reputation: 797
Try split("\n")
.
content = """Quellen: https://sites.google.com/view/sources...
Das Leben zu begreifen ist ziemlich schwierig, weil du immer mittendrin steckst. Es ist, als wolltest du herausfinden wie groß der Ozean ist, während du darin schwimmst. Meistens bist du damit beschäftigt, dich über Wasser zu halten. Es ist also gar nicht so einfach, herauszufinden, was du mit deinem Leben machen und wie du deine Zeit einsetzen willst.
Soundcloud: http://bitlylink
Facebook: http://bitlylink
Twitter: http://bitlylink
Instagram: http://bitlylink"""
description = content.split("\n")[2]
print(description)
Upvotes: 1
Reputation: 119
Seems to me like you just want to use the specific line:
f = open('your_file_name')
lines = f.readlines()
print(lines[3])
Upvotes: 0
Reputation: 914
In order to do what you want, I believe there is some pattern you need to find. I'm not sure what your data could look like but you could try something like this:
description = '\n'.join([line for line in long_str.split('\n') if ': http' not in line and line != ''])
print(description)
This also account for the presence of '\n' in the description
Upvotes: 0