我试图抓取这个有表格的网站。其中一行包含我需要的信息(假设每个单元格看起来像这些条目之一:[12%、34%、27%、38%])
我使用这一行选择了所有这些百分比:
notes = driver.find_elements_by_xpath("//*[contains(text(),'%')]").text
没有比这更好的了;没有可供我选择的类名或 ID 名
我假设这些是百分比的元素,但我如何转换此数组以打印出具有实际百分比的数组(例如 [12%、34%、27%、38%])?
谢谢!
请您参考如下方法:
find_elements_by_xpath(所有 selenium find_elements... 方法返回一个列表)返回一个 Python list,您必须调用 。列表项上的文本,而不是列表本身。
notes = driver.find_elements_by_xpath("//*[contains(text(),'%')]")
notes = [note.text for note in notes]
