【发布时间】:2017-12-25 08:27:34
【问题描述】:
我在 python 中结合 selenium 编写了一个脚本来启动对网页中某个链接的点击。我唯一的目的是点击那个链接。我尝试了几种不同的方法,但无法正常工作。
网页链接:URL
我尝试过的脚本:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get("use_above_url")
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".k-selectable"))).click()
driver.quit()
可点击链接所在的元素:
<div class="k-grid-content k-auto-scrollable">
<table class="k-selectable" data-role="selectable" role="grid" style="touch-action: none;">
<colgroup>
<col style="width:100px"/>
<col style="width:210px"/>
<col/>
<col/>
<col style="width:120px"/>
</colgroup>
<tbody role="rowgroup">
<tr class="rowHover" data-uid="1fccd732-cd65-4393-b1be-66786fe9ee60" role="row">
<td role="gridcell">
R016698
</td>
<td role="gridcell">
R-13-0410-0620-50000
</td>
<td role="gridcell" style="display:none">
O0485204
</td>
<td role="gridcell">
GOOCH, PHILIP L
</td>
<td role="gridcell">
319 LIZZIE ST, TAYLOR, TX 76574
</td>
<td role="gridcell" style="display:none">
DOAK ADDITION, BLOCK 62, LOT 5
</td>
<td role="gridcell" style="display:none">
T541
</td>
<td role="gridcell" style="display:none">
</td>
<td role="gridcell" style="display:none">
S3564 - Doak Addition
</td>
<td role="gridcell" style="display:none">
Real
</td>
<td role="gridcell">
<div style="text-align:right;width:100%">
$46,785
</div>
</td>
</tr>
</tbody>
</table>
</div>
如果您按照上面的 url,那么您可以在该网页中看到包含此确切文本 R016698 R-13-0410-0620-50000 GOOCH, PHILIP L 319 LIZZIE ST, TAYLOR, TX 76574 的一行。那就是我想点击的地方。当您将鼠标悬停在该链接上时,会注意到链接上出现阴影。希望很清楚我想做什么。提前致谢。
【问题讨论】:
标签: python python-3.x selenium selenium-webdriver web-scraping