【发布时间】:2020-02-10 12:50:45
【问题描述】:
我一直在尝试遍历页面上具有定义特征的所有 svg 元素,然后单击它们并进行解析,但只发现了如何打开第一个元素 你知道怎么全部打开吗? 任何反馈表示赞赏:)
<tr class="MuiTableRow-root">
<td class="MuiTableCell-root jss346 MuiTableCell-alignLeft MuiTableCell-sizeSmall MuiTableCell-body">АМАРИЛ М ТАБЛ. П/ПЛЕН/ОБ. 2МГ+500МГ №30</td>
<td class="MuiTableCell-root jss346 MuiTableCell-alignRight MuiTableCell-sizeSmall MuiTableCell-body">1</td>
<td class="MuiTableCell-root jss346 MuiTableCell-alignLeft MuiTableCell-sizeSmall MuiTableCell-body"><a class="MuiTypography-root MuiLink-root MuiLink-underlineHover jss348 MuiTypography-colorPrimary"><svg class="MuiSvgIcon-root jss350" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation"><path d="M18 17H6v-2h12v2zm0-4H6v-2h12v2zm0-4H6V7h12v2zM3 22l1.5-1.5L6 22l1.5-1.5L9 22l1.5-1.5L12 22l1.5-1.5L15 22l1.5-1.5L18 22l1.5-1.5L21 22V2l-1.5 1.5L18 2l-1.5 1.5L15 2l-1.5 1.5L12 2l-1.5 1.5L9 2 7.5 3.5 6 2 4.5 3.5 3 2v20z"></path></svg></a></td>
</tr>
<tr class="MuiTableRow-root">
<td class="MuiTableCell-root jss346 MuiTableCell-alignLeft MuiTableCell-sizeSmall MuiTableCell-body">АМАРИЛ М ТАБЛ. П/ПЛЕН/ОБ. 2МГ+500МГ №30</td>
<td class="MuiTableCell-root jss346 MuiTableCell-alignRight MuiTableCell-sizeSmall MuiTableCell-body">1</td>
<td class="MuiTableCell-root jss346 MuiTableCell-alignLeft MuiTableCell-sizeSmall MuiTableCell-body"><a class="MuiTypography-root MuiLink-root MuiLink-underlineHover jss348 MuiTypography-colorPrimary"><svg class="MuiSvgIcon-root jss350" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation"><path d="M18 17H6v-2h12v2zm0-4H6v-2h12v2zm0-4H6V7h12v2zM3 22l1.5-1.5L6 22l1.5-1.5L9 22l1.5-1.5L12 22l1.5-1.5L15 22l1.5-1.5L18 22l1.5-1.5L21 22V2l-1.5 1.5L18 2l-1.5 1.5L15 2l-1.5 1.5L12 2l-1.5 1.5L9 2 7.5 3.5 6 2 4.5 3.5 3 2v20z"></path></svg></a></td>
</tr>
等等……
我的代码:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("start-maximized")
driver = webdriver.Chrome(options=chrome_options)
driver.get(url)
XPATH = "//*[name()='svg' and contains(@class, 'jss350')]"
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[name()='svg' and contains(@class, 'jss350')]"))).click()
driver.quit()
【问题讨论】: