0

Im extracting some soccer data from a simple dynamic table using Selenium, but the problem is, when im trying to get the "text-center" class name, it shows a lot of extra data that i dont want.

I've tried using xpath and css_selector, but it wont solve the problem.

Site HTML:

Data 1: Score (Wanted result: 0-0)

<td class="text-center">
   <a href="/r/1571269/somedata" id="r_1571269S">0-0</a>
   </td>

Data 2: Odd: (Wanted data: 2.375)

<td class="text-center" id="o_1562530_0">2.375</td>

This is part of my code:


Score = driver.find_element_by_class_name('text-center')
for score in Score:

    print("Score: "+ score.text)


As you can see, they have the same class name, and when i run the script, it appears both togheter plus a lot of extra content with that class name. Also i've tried by finding by id, but the id changes every time so it has no sense. What do you recommend? THanks in advance.

8
  • Could you please post more HTML for the context of those <td> elements? Commented Apr 21, 2019 at 20:25
  • Not sure if i can send links gyazo.com/a79593080dfcbdaef4270a61ce3a7e95 Commented Apr 21, 2019 at 20:30
  • You don't have to post the link. Instead of screenshot copy the block of HTML that contains both of the data you are interested in with possibly one or two levels of parents. Data 1 and 2 are on different tables, right? Commented Apr 21, 2019 at 20:46
  • The html is too long, but they come from a responsive table, and yes, Data 1 and Data 2 are in different tables Commented Apr 21, 2019 at 20:48
  • In plain text, what are you trying to achieve in this page, could you elaborate? Trying to get all the odds and scores? or mapping them? Commented Apr 21, 2019 at 20:54

1 Answer 1

1

The question is really unclear... but... if you have multiple elements that have the same CSS class name, you can find the text in each element like this:

elements = driver.find_elements_by_class_name('text-center')
for element in elements:
    print(element.text)
  • notice the use of find_elements_* rather than find_element_* ... the plural version returns a list of all elements that match.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.