I ran selenium chromedriver and did scrap some text from website. Now the problem is text string is not in proper format.
The string in the code is: selectDescription.text
code:
for link in links:
print "Navigating to link" + link
browser.get(link)
try:
selectDescription = browser.find_element_by_xpath("(//div[@class='md'])[2]")
try:
data['description'].append(selectDescription.text)
except KeyError:
data['description'] = [selectDescription.text]
except NoSuchElementException:
try:
data['description'].append("")
except KeyError:
data['description'] = [""]
continue
For example:
this is is bad
text
I want it to be formatted into: this is bad text
How can I do that? Do I have to remove new line before I insert it into my array? I did try searching, but since I am new to python, some of the stuff is just getting over my head. Any help will be highly appreciated.
Should I be using replace method?