wan mohd payed
wan mohd payed

Reputation: 171

How to split string and make it printed in different line?

I have this link:

http://www.downloadcrew.com/article/14769-free_studio

I have this code:

import urllib
from bs4 import BeautifulSoup
import time

url = "http://www.downloadcrew.com/article/14769-free_studio"
pageUrl = urllib.urlopen(url)
time.sleep(2)
soup = BeautifulSoup(pageUrl)

for b in soup.select("h1#articleTitle"):
    a = b.contents[0].strip()
    print "app_name: "+a

The output is:

app_name: Free Studio 2013 v6.1.12.925

But I need the output to be like this:

app_name: Free Studio 2013
version: v6.1.12.925

How can I possibly do that?

Upvotes: 0

Views: 54

Answers (2)

PascalVKooten
PascalVKooten

Reputation: 21453

You could store the results of the split, and then use "\n".join(your_var) to glue the contents together by newline.

Then you could simply print that result in the shape you want.

Upvotes: 0

Michael Kazarian
Michael Kazarian

Reputation: 4462

Some idea for you:

text = 'app_name: Free Studio 2013 v6.1.12.925'
ver_pos = text.find(' v') #It is token for get version
print '%s \nversion: %s' % (text[:ver_pos], text[ver_pos:])

Result:

app_name: Free Studio 2013 
version:  v6.1.12.925

Upvotes: 1

Related Questions