【发布时间】:2020-03-25 05:02:00
【问题描述】:
尝试创建一个循环遍历我的收件箱并查找所有包含“relative flex”的 div 类的脚本,如果 div 类包含标记为“dn dib-1”的跨度类,则它将以下 href 链接复制并保存到我的列表并移动到下一个 div。
这里是html代码:
<div class="relative flex">
<span class="dn dib-l" style="left: -16px;"</span>
<a href="/conversations/269190401#newest_message" class="flex-auto mv0 f5 fw4 lh-copy light-gray truncate no-underline outline-none">hey how are you?</a>
这是我现在拥有的代码:
link_list = []
sex_list = []
message = browser.find_elements_by_xpath('//*[@class="relative flex"]')
message_new = browser.find_elements_by_xpath('//*[@class="dn dib-l"]')
for item in message:
link = item.find_element_by_xpath('.//a').get_attribute('href')
if message_new in message:
link_list.append(link)
问题: message、message_new 在请求时都包含数据,但是尽管这些类有多个消息,但链接变量仅包含一个元素,而 link_list 不包含任何元素。我需要在我的代码中进行哪些更改才能保存包含此 span 类的 div 类中的所有链接?
【问题讨论】:
标签: python python-3.x selenium selenium-webdriver