-3
driver.get('https://cogos.com/locations')
y = driver.find_elements(By.XPATH, "//*[@class= 'address']")

for a in y:
    b = a.text
    print(b)

Returning:

CoGo’s 450 BP
1610 Gringo Road
Aliquippa
663.07 Miles.
CoGo’s 497 BP
2399 Duss Avenue
Ambridge
666.93 Miles.
CoGo’s 463 BP
1907 Darlington Road
Beaver Falls
668.64 Miles.
CoGo’s 30 Sunoco
6371 Lincoln Highway
Bedford
719.65 Miles.
CoGo’s 809 Exxon
5100 State Route 51
Belle Vernon
667.74 Miles.
abdusco
  • 9,700
  • 2
  • 27
  • 44
Ferron12
  • 1
  • 2

1 Answers1

0

As an option I'd recommend here: extract in the way You do: Do the extraction by Xpath:

//*[@class= 'address']/p

And for each piece of text extracted - split by break-line symbol. html tree view of the page

Per this one -

inputString.splitlines()

Should do the trick;

So in Your case

driver.get('https://cogos.com/locations')
y = driver.find_elements(By.XPATH, "//*[@class= 'address']/p")

for a in y:
    b = a.text
    x = b.splitlines()
    print(x)

Hope this be helpful for You. Regards,

eugene.polschikov
  • 7,254
  • 2
  • 31
  • 44