Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping problem using Selenium
#1
Hi,
I am trying to use Python with Selenium recursively loop through a list and provide a cumulative value of a metric for each 'match' in a list. Although my issue is I am getting the same (incorrect) value for each of the items in the list. Any tips where this is going wrong? I am pretty sure it is the for data in soup.findAll('div',{'class':'ml1-SoccerStatsBar '}): line but not sure why.

#use Selenium & Beautiful Soup
from selenium import webdriver
import time
from bs4 import BeautifulSoup 

#define URL/driver
my_url = "https://www.bet365.com/#/IP/"

driver = webdriver.Edge()
driver.get(my_url)

#allow a sleep of 10 seconds
time.sleep(10)

#parse the page
pSource= driver.page_source
soup = BeautifulSoup(pSource, "html.parser")

#containers tag - per match
containers = soup.findAll("div", {"class": "ipn-TeamStack "})
for container in containers:
    match = container.find_all('div')
    texts = [div.text for div in match]
    #Total Match Shots
    cumul_match_shots = 0 
    for data in soup.findAll('div',{'class':'ml1-SoccerStatsBar '}):    
        for result in data.find_all('span'):            
            a = result.text
            if len(a) > 0:
               cumul_match_shots += int(a)
    #print out values
    print(texts)  
    print(cumul_match_shots) 
 
        
#close the webpage
driver.close()           
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with Selenium webdriver Fred 1 2,030 Jan-10-2022, 05:45 PM
Last Post: Larz60+
  Looping actions in an iframe using Selenium on Python amyd 3 3,003 Mar-06-2019, 08:31 PM
Last Post: Larz60+
  Selenium Webdriver Memory Problem? satbir129 2 6,857 Mar-01-2019, 04:17 AM
Last Post: satbir129
  Pull Down Menu Problem using Selenium ber 1 2,461 Nov-15-2018, 01:22 AM
Last Post: Larz60+
  A problem with using selenium Truman 2 10,543 Aug-08-2018, 10:41 PM
Last Post: Truman
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,618 Nov-03-2017, 08:41 PM
Last Post: metulburr
  Python Selenium WebDriver Problem SlpnGnt 2 7,376 Apr-01-2017, 10:40 PM
Last Post: SlpnGnt
  Running a selenium test using data from spreadsheet (have problem iterating...) danw32 0 3,089 Mar-07-2017, 12:40 PM
Last Post: danw32

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020