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.
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.
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,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.