Dont Want Spaces between paragraphs: Python

I am browsing the news website to receive news articles using the following code:

import mechanize
from selenium import webdriver
from bs4 import BeautifulSoup

url = "http://www.thehindu.com/archive/web/2012/06/19/"

link_dictionary = {}
driver = webdriver.Firefox()
driver.get(url)
soup = BeautifulSoup(driver.page_source)

for tag_li in soup.findAll('li', attrs={"data-section":"Editorial"}):
    for link in tag_li.findAll('a'):
        link_dictionary[link.string] = link.get('href')
        print link_dictionary[link.string]
        urlnew = link_dictionary[link.string]

        brnew =  mechanize.Browser()
        htmltextnew = brnew.open(urlnew).read()

        articletext = ""
        soupnew = BeautifulSoup(htmltextnew)
        for tag in soupnew.findAll('p'):
            articletext += tag.text
        print articletext


driver.close()

I get the desired result, but I want a specific news article in one line. For some articles, I get the whole article in one line, while in others I get different paragraphs. Can someone help me sort out the problem? I am new to python programming. Thanks and respect.

+4
source share
1 answer

, , HTML, , "p" . , , , ( ).

:

import re

, , :

print re.sub('\s+', ' ', articletext, flags=re.M)

, .

+1

All Articles