【发布时间】:2017-04-27 00:17:23
【问题描述】:
以下是我需要唯一 XPath 的 HTML 代码。
<fieldset>
<legend>Type</legend>
<input id="applyremotewhite" name="rvaluetype" checked="checked" value="white" type="radio">
<label for="applyremotewhite">White List</label>
<br>
<br>
<input id="applyremoteblack" name="rvaluetype" value="black" type="radio">
<label for="applyremoteblack">Black List</label>
</fieldset>
<fieldset>
我需要像 [@label = 'White List'] 这样的东西,这样我就不需要在我的代码中编写多个 xpath。我想从函数中传递诸如白名单和黑名单之类的值。
【问题讨论】:
-
这是 HTML。为什么不使用 BeautifulSoup?
-
我对此很陌生。将阅读有关 BeautifulSoup 的信息。
-
如果您是新手,那么您是如何知道 XPath 是什么的,或者您认为为什么需要它?
-
@SaurabhThakkar 如果您使用 beatifulsoup,那么您可以在
fieldset内选择label,其中for属性是applyremotewhite,然后在该标签内选择text。
标签: python xpath html-parsing