在页面上使用硒迭代DIV类

时间:2019-09-28 12:45:57

标签: python selenium

我希望使用硒在页面上的一组行中进行迭代,以快速从页面上抓取实时结果。我有一个似乎可以返回第一行并打印它的代码,但看起来并不遍历集合。

Team 1 
0
0 Team 2

给我结果;

test %>%
  group_by(id) %>%
  summarize(sum_communities = sum(id/id, na.rm = TRUE))

当页面上只有一个匹配项时,这将是预期的结果-但目前有50个匹配项。

我觉得我在这里的方法中缺少了一些东西,这可能很简单,如果是这样的话,我盯着我的脸很抱歉!

1 个答案:

答案 0 :(得分:1)

您在for rows in content:中输入了错误,其中内容是父div,并且您需要行。要遍历所有行,请使用以下代码:

rows = browser.find_elements_by_class_name('event__match')

for row in rows:
    goals = {}
    goals['Home'] = row.find_element_by_class_name("event__participant--home").text.strip()
    goals['Away'] = row.find_element_by_class_name("event__participant--away").text.strip()
    goals['hScore'] = row.find_element_by_class_name("event__scores").text.split("-")[1]
    goals['aScore'] = row.find_element_by_class_name("event__scores").text.split("-")[-1]

    print(goals['Home'],goals['aScore'],goals['aScore'],goals['Away'])