python-2.7 - 尝试使用带有 Python 2.7 的 selenium 驱动程序从网页中提取列表
问题描述
我正在尝试使用 Selenium 驱动程序和 Python 提取存储在网页中的列表。
列表存储为
ol class="My_Favorite_food"
a href="/recipes/cuisine"
li
span style="margin-left: 10px;"South Indian
span style="margin-left: 10px; margin-right: 5px; font-weight: 400;"Tomato Rice/span
span style="font-size: 0.8em;"(TC)/span span style="float: right; margin-right: 10px;"60/span
/span
/li
/a
/ol
我尝试使用“find_elements_by_xpath”但收效甚微。我哪里出错了?我想提取“South Indian”、“Tomato Rice”、60
try:
dropdown_list = br.find_elements_by_xpath('.//ol[@class="My_Favorite_food"]/a[@href="/recipes"]/li')
items = dropdown_list.find_elements_by_tag_name("li")
for item in items:
Print ("Item text: >%s<>" % item.text)
except:
print("That record is not found")
return 0
解决方案
线
items = dropdown_list.find_elements_by_tag_name("li")
尝试在您的“li”标签中搜索“li”项目。将其更改为
items = dropdown_list.find_elements_by_tag_name("span")
应该做的伎俩。
推荐阅读
- javascript - 如何在javascript中使用名为“data”的键访问我的json数组?
- java - 如何在 Android Studio 中连续移动对象
- spring-boot - 每当在邮递员上测试 HTTP POST 请求时,都会收到状态 500 和消息“缺少 URI 模板变量 'rank'”
- python - 如何在 [0,1] 之间生成不同的浮点数
- c++ - 有人可以帮我理解这些参数/参数吗?
- javascript - C# Form WebBrowser 中的 JS UI 卡住了?
- bash - 将 bash 脚本输出重定向到不包括菜单的日志文件
- django - 如何在 django 中将静态添加到我的脚本中
- java - 为什么Java中的for循环是否存在不会有任何区别
- mysql - 如何在 Rails 应用程序中更改数据库