driver.get('https://cogos.com/locations')
y = driver.find_elements(By.XPATH, "//*[@class= 'address']")
for a in y:
b = a.text
print(b)
返回:
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.
答案 0 :(得分:0)
作为一种选择,我建议在这里: 提取方式如下: 通过Xpath提取:
//*[@class= 'address']/p
每this one-
inputString.splitlines()
应该做到这一点;
所以就您而言
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)
希望这对您有所帮助。 问候