可以在Selenium Python中获取元素的文本
我正在尝试获取一个元素的文本,当我运行它时,它为我提供了一些元素的文字,其中一些元素没有。我不知道为什么会发生这种情况?
# Type and Tags
details_info = []
types = WebDriverWait(driver, 10).until(
EC.presence_of_all_elements_located((By.TAG_NAME, "span")))
for i in range(0, 19):
if types[i].text:
if types[i].text in reference:
details_info.append(types[i].text)
# Types
type_info = []
for d in details_info:
if type(d) is str:
if d in type_legend:
type_info.append(d)
info.append(type_info)
# Tags
tag_info = []
for t in details_info:
if type(t) is str:
if t in tag_legend:
tag_info.append(t)
info.append(tag_info)
I am trying to get the text of an element and when I run it, it gives me the text for some of the elements and some it doesn't. I can't figure out why this is happening?
# Type and Tags
details_info = []
types = WebDriverWait(driver, 10).until(
EC.presence_of_all_elements_located((By.TAG_NAME, "span")))
for i in range(0, 19):
if types[i].text:
if types[i].text in reference:
details_info.append(types[i].text)
# Types
type_info = []
for d in details_info:
if type(d) is str:
if d in type_legend:
type_info.append(d)
info.append(type_info)
# Tags
tag_info = []
for t in details_info:
if type(t) is str:
if t in tag_legend:
tag_info.append(t)
info.append(tag_info)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用以下一个
查看差异在这里
You have to use one of the following
see differences here