https://www.fire.ca.gov/incidents/2018/[在此处输入图像描述][1]
[1]:https://i.stack.imgur.com/c6Z5K.png**strong文本**
这个想法是试图把所有被烧毁的英亩数都写在31页纸上。尝试使用常规单击和JS单击,但均失败。没有错误报告,只是按钮不起作用——它从未离开第一页,所以基本上我得到了31次相同的数字
任何有用的建议都会非常感激,因为我花了整整一天的时间试图点击几个该死的按钮
for i in range(31):
records = driver.find_elements_by_class_name('responsive-table-row')
for n in range(1,11):
record_single = records[n].find_elements_by_class_name('responsive-table-cell')
try:
acres = record_single[3].find_element_by_tag_name('span').text
except:
acres = 'N/A'
ws.append([acres])
buttons = driver.find_element_by_class_name('pagination-navigation')
button_parent = buttons.find_element_by_tag_name('ul')
button_list = button_parent.find_elements_by_tag_name('li')
if i <30:
#button_list[i+1].click
driver.execute_script('arguments[0].click()',button_list[i+1])
time.sleep(3)
按钮列表包含li的
您的脚本正在尝试单击列表项(li)结构,而不是其中的锚点(a)。 如果你看来源,li不包含任何内容。锚包含javascript href,应该触发事件以导航页面
在您的解决方案中,在最后的循环中,您需要执行以下操作:
或者,您可以将所有这些发现合并到一个xpath中。打开chromedevtools,按control+f并输入以下内容: [编辑]更新的xpath
这将创建一个所有李的列表
[edit]添加了此位
此外,您可以将
/a
添加到末尾,并直接创建按钮列表(仍然使用find elements):在我的开发工具中,这与31个元素相匹配
它返回多个匹配项,您可以使用它填充按钮列表。有很多资源可以帮助您学习如何使用xpath—只需使用Google:-)
相关问题 更多 >
编程相关推荐