how can I remove redundant spacing after I pull some element data with selenium
My output lookslike:
Telefon:
216 593 17 20 - 21 - 22
Websitesi:
http://www.an-ko.com
Email:
[email protected]
and I want to remove spaces from this here's the script I use
from selenium import webdriver
driver = webdriver.Safari()
driver.get("https://iayosb.com/firmalar/anadolu-kompozit-mam-san-ve-tic-a-s/")
article = driver.find_elements_by_xpath("//div[@class='w2dc-fields-group w2dc-fields-group-1']")
for elem in article:
print(elem.text)
driver.quit()
Thanks is advance I really appreciate it
CodePudding user response:
I'm using pycharm and for trailing spaces I am using replace(' ', '')
. Please see below :
driver.get("https://iayosb.com/firmalar/anadolu-kompozit-mam-san-ve-tic-a-s/")
article = driver.find_elements_by_xpath("//div[@class='w2dc-fields-group w2dc-fields-group-1']")
for elem in article:
print(elem.get_attribute('innerText').replace(' ', ''))
Output :
İLETİŞİMBİLGİLERİ
Telefon:2165931720-21-22
Websitesi:http://www.an-ko.com
Email:[email protected]