【发布时间】:2020-09-08 11:19:17
【问题描述】:
这是我要抓取的 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' )
这就是我尝试通过“选项标签”属性提取颜色的方式
【问题讨论】:
-
请阅读为什么是screenshot of HTML or code or error is a bad idea。考虑使用基于格式化文本的相关 HTML、代码试验和错误堆栈跟踪来更新问题。
-
另外,可以分享一下网页的网址吗?
-
完成你建议的更改@DebanjanB
标签: python selenium web-scraping attributes element