0

I am using ScraPy to get some information from a site and am getting a string back that looks like this:

[u'Oxfam-America Inc. \n            ']

What I need is to get just the "Oxfam-America Inc." part back. Suggestions?

1 Answer 1

4
>>> [u'Oxfam-America Inc. \n            '][0].strip()
u'Oxfam-America Inc.'

The method you want is .strip(). The problem is compounded because what you are getting back is a list, not a string, so you have to first access the 0th element in the list, then call the .strip() method on that string.

So for example if the variable assigned to the list you showed in the question were assigned to field you could print it with the following..

field = [u'Oxfam-America Inc. \n            ']
stripped_text = field[0].strip()
print stripped_text
Sign up to request clarification or add additional context in comments.

4 Comments

This is a step in the right direction, but I need ONLY Oxfam-America Inc.
What about the u at the beginning?
That isn't part of the string.. that's just a notational device to let you know that the object is a unicode string.
Also, what does strip() do exactly? It looks like it removes all returns and extra characters?

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.