我想在此页面的标题中获取文本:
iShares FTSE MIB UCITS ETF EUR(Dist)
标签看起来像这样:
<h1 class="product-title" title="iShares FTSE MIB UCITS ETF EUR (Dist)"> iShares FTSE MIB UCITS ETF EUR (Dist) </h1>
Run Code Online (Sandbox Code Playgroud)
我正在使用这个xPath:
xp_name = ".//*[@class[contains(normalize-space(.), 'product-title')]]"
Run Code Online (Sandbox Code Playgroud)
.text在Selenium WebDriver for Python中检索:
new_name = driver.find_element_by_xpath(xp_name).text
Run Code Online (Sandbox Code Playgroud)
驱动程序找到xpath,但是当我打印时new_name,macOS Terminal只打印一个空字符串:""
这可能是什么原因?
注意:我还尝试了一些其他的xpath替代方案,获得相同的结果,例如:
xp_name = ".//*[@id='fundHeader']//h1"
Run Code Online (Sandbox Code Playgroud)