未找到Selenium Python元素

2024-05-29 02:37:35 发布

您现在位置:Python中文网/ 问答频道 /正文

这是一个指向HTML的链接,我想刮取https://pk.khaadi.com/unstitched/r20206-red-r20206-red-pk.html

<div class="swatch-attribute-options clearfix">
      <div class="swatch-option color selected" option-type="1" option- 
       id="61" option-label="RED" option-tooltip-thumb="" option-tooltip- 
       value="#ee0000" "="" style="background: #ee0000 no-repeat center; 
       background-size: initial;">
      </div>
      <div class="swatch-option color selected" option-type="1" option- 
       id="73" option-label="YELLOW" option-tooltip-thumb="" option-tooltip- 
       value="#feed00" "="" style="background: #feed00 no-repeat center; 
       background-size: initial;">
      </div>
</div>
Color = S_Driver.find_elements_by_xpath( '//*[@id="product-options-wrapper"]/div/div/div[1]/div' )

Xpath是两个颜色div都存在的外部div

            for c in Color:
            n_Color.append(c.get_attribute( 'option-label' ))
            print( n_Color + '\n' )

这就是我试图通过“选项标签”属性提取颜色的方法


Tags: dividattributeredlabelclasscoloroptions
1条回答
网友
1楼 · 发布于 2024-05-29 02:37:35

将xpath更改为:

//div[@class='swatch-option color']

根据提供的屏幕截图创建,希望页面上没有基于此截图的其他匹配项。如果是,请更改为:

//div[@class='swatch-option color' and @option-type='1']

相关问题 更多 >

    热门问题