0

The output itself is working but how can i format the output or write it to a variable or array using outside the for loop ?

...
for item in soup.findAll('span', {"itemprop":"actor"}):
    print item.text
...

Output example:

Sylvester Stallone
Arnold Schwarzenegger

But Output should look something like:

Actors: Sylvester Stallone, Arnold Schwarzenegger

3 Answers 3

2
actor_list = soup.findAll('span', {"itemprop":"actor"})
print "Actors: {0}".format(", ".join(actor_list))
Sign up to request clarification or add additional context in comments.

Comments

1

One thing you can do is this...

actors = [item.text for item in soup.findAll('span', {"itemprop":"actor"})]
print "Actors: %s" % (", ".join(actors))

Comments

0

Without save it to a variable:

print "Actors: ",
...
for item in soup.findAll('span', {"itemprop":"actor"}):
    print item.text, ",",
...

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.