cannot get p class=info <span> tag data from beautifulsoup

Cannot get the tag data, cannot get p class=info tag data from beautifulsoup thanks !

from bs4 import BeautifulSoup 
import re

html = """"
<p class="info">
<span>Kranji Mile Day simulcast races, 
Kranji Racecourse, SIN</span>
<span>Class 3 Handicap   -  1200M TURF</span>
<span>Saturday, 26 May 2018</span>
<span>Race 1, 5:15 PM</span>
</p>
"""
soup = BeautifulSoup(html, "html.parser")
table = soup.find('p', attrs={class:'info'})
rows = table.findAll("span")

print rows

expected output seperate by commas

Kranji Mile Day simulcast races, Kranji Racecourse, SIN , Class 3, Handicap, 1200M, TURF, Saturday, 26 May 2018, Race 1, 5:15PM

Once you resolve the class problem, as explained in the other answer, you still have to extract strings from the tags:

result = ', '.join(r.string for r in rows)
print(result)
#Kranji Mile Day simulcast races, 
# Kranji Racecourse, SIN, Class 3 Handicap   -  1200M TURF, Saturday, 26 May 2018, Race 1, 5:15 PM

How to get the element by class? htmlunit, <div class="info-list"> <span>Tel:</span> <p>+111 1111 2222</p> </div> of div '@class' indicates attribute name, we can use @id, @name etc. we need to pass all class names here, only 'class1' doesn't work here. A citation Class P could both mean either a municipal minor citation or a petty traffic citation and is usually is issued by a municipal officer for the village or town. The best course of action would be to remedy the said condition, take photographic evidence of compliance to court and the village prosecutor may dismiss the citation.

it is class_ because class is reserved keyword

table = soup.find('p', attrs={'class':'info'})

table = soup.find('p',class_='info'})

Use text attribute it concatenates all text inside the tag

string attribute will not working if it contains another tag inside it

print (', '.join(i.text for i in rows)) # For getting text 

Beginning JSP, JSF and Tomcat: Java Web Development, <c:choose> 33: <c:when test="${orderID > 0}"> 34: <p class="info"> 35: Thank can make assignments and execute methods, while EL expressions cannot. The .class selector selects elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class.

Hm - in python3 this works fine for me if you just quote 'class' in this line

table = soup.find('p', attrs={'class':'info'})
                          ^

though the output will be the ... elements rather than just the text. Do you want the elements or only the text?

Little CSS Stuff Newcomers Get Confused About, Put them together with a space and you get “select any div that is a descendant of any element with this class name”. The second doesn't involve any of that  A small adhesive piece of paper of specified value issued by a postal authority to be affixed to a letter or a parcel to indicate the amount of postage paid. These stamps are the most commonly used stamps and have a fixed amount of postage noted on them. The following is a list of the most common types of postage stamps:

I can't get the lightbox to work can anyone help?, <div id="extra-info" class="glass"> <h2>We'll Pay the Call</h2> <p>No waiting about either Click and we'll connect you instantly! How's that  Seesaw works great on any computer or device. For the best experience, bookmark app.seesaw.me on your computer. Then download the right version of the Seesaw app for your device and your students' devices. Look for Seesaw: The Learning Journal in the app stores. Click below to download the right app for your devices:

freeCodeCamp Challenge Guide: Change the Font Size of an , We need to create an entry for p elements and set the font-size to 16 pixels ( 16px ), Inside the same <style> tag that contains your red-text class. Example: h1 { font-​size: I just started with the course and can't seem to get past this point either. Definition of cannot. : can not. cannot but or cannot help but or less commonly cannot help. : to be unable to do otherwise than we cannot but wonder why I cannot help feeling sorry for them.

WebD2: Understanding ID and Class in CSS, In this lesson you will learn how ID and Class attributes can be used to stylize individual In the above example, we use "p#alert" as the selector, which tells the The third div is a container for information about your course and school. Exception: At col 3: Cannot get symbol location information. No object location info found in DWARF data I am trying to debug the FreeRtos/LWIP echoserver that has been ported to my hardware.

Comments
  • it is class_ bcos class is reserved keyword