我正在尝试从以下代码中提取2个数据。任何人都可以告诉我Selenium webdriver代码来解析它。
要获取的数据:
以下是存在数据的HTML代码。
<div class="content">
<div class="swatch-container">
<div class="product-carousels swatch-carousel">
<div class="caro typeB swatchContainerHeight" data-touch-skip-components-init="true" data-carousel="{" single " : false, "title " : true, "wrap " : ".custom-wrap ", "prev " : "Prev ", "next " : "Next ", "preset " : "PDP_SWL_STD "}" data-alt-image-text="Default Alt">
<ul class="custom-wrap swatches grid-variant-swatches">
<li class="all ">
<li class="all active-swatch">
<div class="selected-swatch" />
<input id="Sapphire" type="radio" data-subset-viewer="http://www.marksandspencer.com/MSLightboxDisplayView?catalogId=10051&langId=-24&productId=2559515&storeId=10151" data-alt-image-text="Sapphire Pure Cotton T-Shirt with StayNEW™ Clothing" data-image-set="//asset1.marksandspencer.com/is/image/mands/T41_4350_X9_IS?req=imageset,json&id=T41_4350_X9_IS" data-dressipi="sapphire" value="Sapphire" name="colour" checked="checked" />
<label class="colour-1 lazy" style="background-image:url(//asset1.marksandspencer.com/is/image/mands/SD_01_T41_4350_X9_X_EC_88?$PDP_SWL_STD$)" data-swatch-name="Sapphire" for="Sapphire">
<span class="glimmer-container" />
</label>
</li>
以下是我正在使用的代码:
WebElement productname = driver.findElement(By.className("content").className("colour-1 lazy"));
String image = productname.getAttribute("Style");
System.out.println(image);
答案 0 :(得分:0)
我不确定我是否有足够的信息来提供最佳答案,但我可以根据您提供的内容提供答案。
您要求的所有数据都在-- TODO: Only include the SET IDENTITY_INSERT lines if your table has an identity column
--SET IDENTITY_INSERT MyTable ON
INSERT MyTable
SELECT *
FROM #MyTableBackup
--SET IDENTITY_INSERT MyTable OFF
-- TODO: If you disabled foreign key constraints in the pre-deployment script, enable them here.
DROP TABLE #MyTableBackup
标记中。您可以使用CSS选择器LABEL
找到它,这意味着找到具有类(。)label.colour-1
的{{1}}标记。获得元素后,您可以获取颜色名称Sapphire的LABEL
属性。然后,您将获得colour-1
属性并为URL部分解析它。
data-swatch-name