1

I'm making an Selenium project for fun. I want see all football score on my terminal. I use Selenium for scraping. But I cannot print the scraped element. How can I fix that?

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import os
from bs4 import BeautifulSoup
import lxml


team_both = []
team_one = []
team_two = []
team_id = []

driver = webdriver.Chrome(ChromeDriverManager().install())
time.sleep(1)
#os.system('clear')
time.sleep(1)
driver.get('https://www.bet365.de/#/IP/B1')

time.sleep(1)

try:
    driver.find_element_by_class_name('iip-IntroductoryPopup_Cross').click()
except:
    pass

time.sleep(1)

# Scroll to bottom
element = driver.find_element_by_class_name("ovm-OverviewScroller-enabled")
actions = ActionChains(driver)
actions.move_to_element(element).click_and_hold().perform()

soup = BeautifulSoup(driver.page_source, 'lxml')

time.sleep(5)
os.system('clear')
#ovm-FixtureDetailsTwoWay_TeamName 
teams = soup.find_all('div' , {"class" : "ovm-FixtureDetailsTwoWay_TeamName "})
for i in teams:
    print(i.text)
1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Mar 9, 2022 at 9:14

1 Answer 1

0

The simplest way to extract a text from web element is by applying the .text method, but since you are using find_all method, the team_both is not a single web element rather a list of web elements.
In order to get texts from the web elements in a list you have to iterate over the elements in the list and extract text from each element, as following:

team_both = soup.find_all('div', {"class" : "ovm-FixtureDetailsTwoWay_TeamName"})
for team in team_both:
    print(team.text)
Sign up to request clarification or add additional context in comments.

6 Comments

i tried this but it doesn't work
What exactly is the result now? Some error, just empty lines?
try maximizing the driver window size, put the time.sleep(5) before soup = BeautifulSoup(driver.page_source, 'lxml')
it don't work I don't have any result
Browser not opened at all?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.