我正在尝试将css重写为XPATH。 css 缩短为:
div:nth-child(1) > .lay-selection-button span.bet-button-price
我正在尝试编写一个等效的 xpath。
//div[1]/button[starts-with(@class=’lay-selection-button span.bet-button-price’)]//span[@class=’bet-button-price’]
知道为什么它不起作用。
它来自这个网站或图像在这里
完整的 css 是:
#main-wrapper > div > div.scrollable-panes-height-taker > div > div.page-content.nested-scrollable-pane-parent > div > div > div > div.content-page-center-column.coupon-center-column > div > div:nth-child(1) > main > ng-include:nth-child(3) > section.coupon-card.coupon-card-first > div.card-content > bf-coupon-table > div > table > tbody > tr:nth-child(1) > td.coupon-runners > div:nth-child(1) > button.bf-bet-button.lay-button.lay-selection-button > div > span.bet-button-price
缩短为:
div:nth-child(1) > button.bf-bet-button.lay-button.lay-selection-button > div > span.bet-button-price
最后我在顶部拥有的:
div:nth-child(1) > .lay-selection-button span.bet-button-price
您可以使用
以下代码从第一个蓝色列中获取所有price
值:
for cell in driver.find_elements_by_xpath('//div[1]/button[@price][1]'):
print(cell.get_attribute('price'))
对于第一个粉红色列:
for cell in driver.find_elements_by_xpath('//div[1]/button[@price][2]'):
print(cell.get_attribute('price'))
如果您想获取size
值而不是price
- 只需将cell.get_attribute('price')
替换为cell.get_attribute('size')
您可以使用//div[2]
从第二个蓝色/粉红色列中获取值,//div[3]
获取第三个列的值
这里是 xpath,不是为了编写额外的代码:
//tr//*[contains(@class,'coupon-runner')][1]/button[2]//span[contains(@class,'bet-button-price')]