本帖最后由 sjjy1813 于 2023-3-7 11:36 编辑
<table cellspacing="0" cellpadding="0" border="0" class="el-table__body" style="width: 1013px;"><colgroup><col name="el-table_3_column_9" width="516"><col name="el-table_3_column_10" width="120"><col name="el-table_3_column_12" width="120"><col name="el-table_3_column_11" width="257"></colgroup><tbody><tr class="el-table__row"><td rowspan="1" colspan="1" class="el-table_3_column_9 "><div class="cell"><!----> <div data-v-01ceff70="" data-v-3cd85bb6="" class="doc-type-icon doc"></div> <span data-v-3cd85bb6="" style="cursor: pointer;">
房管局购房协议正文
</span></div></td><td rowspan="1" colspan="1" class="el-table_3_column_10 is-center table-status"><div class="cell"><span data-v-3cd85bb6="" class="dot not-pass"></span> <span data-v-3cd85bb6="" style="margin-left: 6px;">未通过</span> <i data-v-3cd85bb6="" class="el-tooltip el-icon-warning-outline" aria-describedby="el-tooltip-2112" tabindex="0"></i></div></td><td rowspan="1" colspan="1" class="el-table_3_column_12 is-center "><div class="cell">8.00</div></td><td rowspan="1" colspan="1" class="el-table_3_column_11 is-center "><div class="cell"><button data-v-3cd85bb6="" type="button" class="el-button el-tooltip el-button--default el-button--mini" aria-describedby="el-tooltip-6024" tabindex="0" style="display: none;"><!----><!----><span>
查看原因
</span></button> <button data-v-3cd85bb6="" type="button" class="el-button el-tooltip disabled-btn el-button--default el-button--mini" aria-describedby="el-tooltip-6723" tabindex="0" style="display: none;"><!----><!----><span>编辑
</span></button> <button data-v-3cd85bb6="" type="button" class="el-button el-button--default el-button--mini" style="display: none;"><!----><!----><span>编辑
</span></button> <button data-v-3cd85bb6="" type="button" class="el-button el-button--default el-button--mini"><!----><!----><span>
下载
</span></button> <button data-v-3cd85bb6="" type="button" class="el-button el-button--default el-button--mini"><!----><!----><span>删除
</span></button></div></td></tr><tr class="el-table__row"><td rowspan="1" colspan="1" class="el-table_3_column_9 "><div class="cell"><!----> <div data-v-01ceff70="" data-v-3cd85bb6="" class="doc-type-icon doc"></div> <span data-v-3cd85bb6="" style="cursor: pointer;">
这里面想选出所有文件名,及其对应的状态未通过、已上架、未上架、审核中,还有文件编辑、下载、删除,然后查找出操作功能的编辑、删除、下载,接着是筛选未上架、未通过的状态文件,通过删除操作,将其删除,不知道怎么了,代码总是无法执行。
# 使用BeautifulSoup来解析页面
soup = BeautifulSoup(driver.page_source, 'html.parser')
# 查找文件名和状态
file_names = []
statuses = []
for td in soup.find_all('td', {'class': 'el-table_3_column_9'}):
file_names.append(td.find('span', {'class': 'cell'}).text.strip())
for td in soup.find_all('td', {'class': 'el-table_3_column_10 is-center table-status'}):
statuses.append(td.find('span', {'class': 'cell'}).text.strip())
# 查找编辑、下载、删除按钮
buttons = {}
for td in soup.find_all('td', {'class': 'el-table_3_column_11 is-center'}):
button_dict = {}
for button in td.find_all('button', {'class': 'el-button el-button--default el-button--mini'}):
button_text = button.find('span').text.strip()
button_dict[button_text] = button
buttons[td.parent.index(td)] = button_dict
# 筛选状态只有未上架和未通过的文件名,并使用删除按钮
for i, status in enumerate(statuses):
if status in ['未上架', '未通过']:
delete_button = buttons[i]['删除']
delete_button.click()
# 弹出确认窗口,点击确认
driver.switch_to.alert.accept()
# 关闭webdriver
driver.quit()
|