遍历selenium中的div(python)

时间:2019-10-31 01:49:16

标签: python-3.x selenium

嗨,我正在使用python在硒中制造刮刀。网络的结构:

enter image description here

我想得到所有的价格和一天。但是我什至不能将div作为可迭代对象捕获,因为下面的代码返回TypeError“对象不可交互” ...:

months = driver.find_element_by_xpath(".//div[@id='departure-calendar']")
for day in months:
    daily_price=driver.find_element_by_xpath(".//span[@class='value']")
    print(daily_price.text)

我在做什么错?我花了几个小时来寻找问题的答案,但找不到。预先感谢您的帮助。

//编辑 感谢@xxMrPHDxx 哇!

prices = driver.find_elements_by_xpath(".//span[@class='value']")    
for p in prices:
    print(p.text)

1 个答案:

答案 0 :(得分:0)

对于months,您可能希望使用find_elements_by_xpath函数来返回列表