1

So what I'm trying to do is use python to parse through articles on pull all the quotes. I used beautiful soup to pull the html from the site, now I'm trying to use split to print everything that is in quotes.

For example, go from:

I like quotes but especially "have problems"

to go to

have problems

2 Answers 2

2

Or re.findall(r'"([^"]*)"',s), demo:

>>> import re
>>> s='I like quotes but especially "have problems"'
>>> re.findall(r'"([^"]*)"',s)
['have problems']
>>> 

regex is your clear friend,

https://docs.python.org/3/howto/regex.html

https://docs.python.org/3/library/re.html?highlight=findall#re.findall

Sign up to request clarification or add additional context in comments.

Comments

1

You can slice the list returned by str.split:

s = 'I like quotes but especially "have problems" and "need more quotes"'
s.split('"')[1::2]

This returns:

['have problems', 'need more quotes']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.