Home > Enterprise >  How Do I get the Text Only From This Class ID With Span in Middle?
How Do I get the Text Only From This Class ID With Span in Middle?

Time:10-25

The below text returns on the divs with that class, but I want the quarter and time left separately.

I tried to do .text, but it gives me the attribute error. How would I get the text only since part of the quarter text is separated by a span tag? Ex...3rd Quarter x:xx looks like:

div

"3"

<span RD span

" x:xx"

div

import pandas as pd
from bs4 import BeautifulSoup
import requests
import lxml


cbs_scores = requests.get('https://www.cbssports.com/college-football/scoreboard/', 'r').text
soup = BeautifulSoup(cbs_scores, 'lxml')

time_left = soup.find_all('div', class_ = 'game-status emphasis')

print(time_left)

CodePudding user response:

I'm getting the following output:

import pandas as pd
from bs4 import BeautifulSoup
import requests
import lxml


cbs_scores = requests.get('https://www.cbssports.com/college-football/scoreboard/', 'r').text
soup = BeautifulSoup(cbs_scores, 'lxml')

for  time_left in soup.find_all('div', class_ = 'game-status emphasis'):
    print(time_left.get_text())

            

Output:

            4th 8:49


            3rd 7:52


            3rd 2:19


            3rd 7:55


            3rd 3:09


            3rd 6:37


            3rd 5:31


            End 3rd 


            4th 12:15


            3rd 4:30


            3rd 11:27


            3rd 7:40


            3rd 11:54


            3rd 12:45


            End 2nd


            End 2nd
  • Related