I have tried to extract text from html page using traditional beautiful soup method. I have followed the code from another SO answer.
import urllib
from bs4 import BeautifulSoup
url = "http://orizon-inc.com/about.aspx"
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
# kill all script and style elements
for script in soup(["script", "style"]):
script.extract() # rip it out
# get text
text = soup.get_text()
# break into lines and remove leading and trailing space on each
lines = (line.strip() for line in text.splitlines())
# break multi-headlines into a line each
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
# drop blank lines
text = '\n'.join(chunk for chunk in chunks if chunk)
print(text)
I am able to extract text using this correctly for most of the pages. But I there occurs new line between the words in the paragraph for some particular pages like the one I've mentioned.
result:
\nAt Orizon, we use our extensive consulting, management, technology and\nengineering capabilities to design, develop,\ntest, deploy, and sustain business and mission-critical solutions to government\nclients worldwide.\nBy using proven management and technology deployment\npractices, we enable our clients to respond faster to opportunities,\nachieve more from their operations, and ultimately exceed\ntheir mission requirements.\nWhere\nconverge\nTechnology & Innovation\n© Copyright 2019 Orizon Inc., All Rights Reserved.\n>'
In the result there occurs a new line between technology and\nengineering, develop,\ntest,etc.
These are all the text inside the same paragraph.
If we view it in html source code it is correct:
<p>
At Orizon, we use our extensive consulting, management, technology and
engineering capabilities to design, develop,
test, deploy, and sustain business and mission-critical solutions to government
clients worldwide.
</p>
<p>
By using proven management and technology deployment
practices, we enable our clients to respond faster to opportunities,
achieve more from their operations, and ultimately exceed
their mission requirements.
</p>
What is the reason for this? and how can I extract it accurately?