0
我使用Python /硒与铬webdriver的,我试图找回根据其他<td>
内容从一个<td>
的URL。我的标记看起来像:传递字符串从JS到Python硒
<div class="targetclass">
<tr>
<td><a href="[email protected]">emailval2</a></td>
<td><a href="[email protected]">emailval</a></td>
</tr>
</div>
这是很容易与jQuery和脚本执行:
with open('jquery-3.2.1.min.js', 'r') as jquery_js:
jquery = jquery_js.read() #read the jquery from a file
driver.execute_script(jquery) # activate the jquery lib
driver.execute_script("$('div.targetclass a[href$=\"[email protected]\"]').parents(\"tr\").find(\"a:first\").attr('href')")
然而,当我尝试存储返回HREF与webdriver的使用,我有以下结果:
aurlval = driver.execute_script("$('div.targetclass a[href$=\"[email protected]\"]').parents(\"tr\").find(\"a:first\").attr('href')")
print (aurlval)
返回的值是
None
如何存储目标网址([email protected]
),以便我可以使用webdriver操作它?
我打在.parent行路障,我想这是因为.parent在硒使用不同。它看起来像我可能需要xpath来实现这一点。 – Marcatectura