Home > Software design >  How can I get a data from in div class using a BeautifulSoup
How can I get a data from in div class using a BeautifulSoup

Time:11-02

I am learning BS4. I parsed some div class. But I want to get data in div code. `

[<div  data-enrollment='{"available":{"id":21313,"enrollmentStatus":{"status":{"code":"C","description":"Closed"},"enrolledCount":17,"reservedCount":0,"waitlistedCount":0,"minEnroll":0,"maxEnroll":17,"maxWaitlist":0,"openReserved":0}},"history":{"id":21313,"enrollmentStatus":{"status":{"code":"C","description":"Closed"},"enrolledCount":17,"reservedCount":0,"waitlistedCount":0,"minEnroll":0,"maxEnroll":17,"maxWaitlist":0,"openReserved":0}}}' data-image='{"imagePath":"/sites/default/files/styles/xlarge/public/COLWRIT-18-2.jpeg","uri":"public://COLWRIT-18-2.jpeg"}' data-json='{"id":21313,"number":"003","component":{"code":"SEM","description":"Seminar"},"displayName":"2023 Spring COLWRIT R4B 003 SEM 003","instructionMode":{"code":"P","description":"In-Person Instruction"},"type":{"code":"E","description":"Enrollment","formalDescription":"Enrollment Section"},"academicOrganization":{"code":"COLWRIT","description":"College Writing Programs","formalDescription":"College Writing Programs"},"academicGroup":{"code":"CLS","description":"L&amp;S","formalDescription":"College of Letters and Science"},"startDate":"2023-01-17","endDate":"2023-05-05","status":{"code":"A","description":"Active"},"association":{"primary":true,"primaryAssociatedComponent":{"code":"SEM","description":"Seminar"},"primaryAssociatedSectionId":21313,"primaryAssociatedSectionIds":[21313],"associatedClass":3},"enrollmentStatus":{"status":{"code":"C","description":"Closed"},"enrolledCount":17,"reservedCount":0,"waitlistedCount":0,"minEnroll":0,"maxEnroll":17,"maxWaitlist":0,"openReserved":0},"printInScheduleOfClasses":true,"addConsentRequired":{"code":"N","description":"No Special Consent Required"},"dropConsentRequired":{"code":"N","description":"No Special Consent Required"},"graded":true,"feesExist":false,"roomShare":false,"sectionAttributes":[{"attribute":{"code":"CCLV","description":"CRSE LEVEL","formalDescription":"Academic Course Level"},"value":{"code":"UGLD","description":"UG Lower Division","formalDescription":"Undergraduate Lower Division Course"}},{"attribute":{"code":"FLEX","description":"FLEX","formalDescription":"Flexible Scheduling Approved"},"value":{"code":"FULLFLEX","description":"All Formats Regardless of Term","formalDescription":"Approved Flex Sched of all Formats for any Term"}},{"attribute":{"code":"TIE","description":"Instr Type","formalDescription":"Instructional Activity Types"},"value":{"code":"SEMT","description":"Seminar-Topical","formalDescription":"Transmitting the Knowledge Base"}},{"attribute":{"code":"VUOC","description":"VCREDIT","formalDescription":"Variable Units of Credit"},"value":{"code":"F","description":"Fixed","formalDescription":"Fixed Unit 1 Value"}},{"attribute":{"code":"NOTE","formalDescription":"Class Notes"},"value":{"code":"2","formalDescription":"Enrollment is restricted to students who have satisfied the first half of the Reading and Composition requirement.  This course satisfies the second half of the Reading and Composition requirement."}},{"attribute":{"code":"NOTE","formalDescription":"Special Title"},"value":{"code":"4","formalDescription":"The High Stakes in Sports Culture"}},{"attribute":{"code":"NOTE","formalDescription":"Class Description"},"value":{"code":"6","formalDescription":"Don\u2019t worry, you don\u2019t necessarily have to be athletic to take this class- you don\u2019t even have to like sports (although you can)! Sports is based on ability and talent, but it can deviate, influenced by various social structures. Key questions guiding the course include: what is the role of sports in politics and activism? How is the culture of sports disneyfied and commercialized? Is sports journalism evolving? How do fans impact the culture? In this course, we\u2019ll explore this divergence in the culture of sports and its relationship with journalism, media, gentrification, body and fandom."}}],"roomCharacteristics":[{"code":"04","description":"AV-Computer Data Display","quantity":1},{"code":"09","description":"AV-DVD Player","quantity":1},{"code":"51","description":"Seating-Movable Desks","quantity":1}],"meetings":[{"number":1,"meetsDays":"MoWeFr","meetsMonday":true,"meetsTuesday":false,"meetsWednesday":true,"meetsThursday":false,"meetsFriday":true,"meetsSaturday":false,"meetsSunday":false,"startTime":"11:00:00","endTime":"11:59:00","location":{"code":"SOCS118","description":"Social Sciences Building 118"},"building":{"code":"1761","description":"Social Sci"},"assignedInstructors":[{"assignmentNumber":1,"instructor":{"identifiers":[{"type":"campus-uid","id":"972764","disclose":true}],"names":[{"type":{"code":"FRM","description":"Former"},"familyName":"Asakawa","givenName":"Chisako","formattedName":"Chisako  Asakawa","disclose":false,"uiControl":{"code":"N","description":"Do Not Display"},"fromDate":"2014-07-07"},{"type":{"code":"PRF","description":"Preferred"},"familyName":"Cole","givenName":"Chisako","formattedName":"Chisako A Cole","disclose":true,"uiControl":{"code":"U","description":"Edit - No Delete"},"fromDate":"2020-06-08"},{"type":{"code":"PRI","description":"Primary"},"familyName":"Cole","givenName":"Chisako","formattedName":"Chisako A Cole","disclose":true,"uiControl":{"code":"D","description":"Display Only"},"fromDate":"2020-06-08"}]},"role":{"code":"PI","description":"1-TIC","formalDescription":"Teaching and In Charge"},"contactMinutes":0,"printInScheduleOfClasses":true,"gradeRosterAccess":{"code":"A","description":"Approve","formalDescription":"Approve"}}],"startDate":"2023-01-17","endDate":"2023-05-05","meetingTopic":[]}],"class":{"course":{"identifiers":[{"type":"cs-course-id","id":"104067"}],"subjectArea":{"code":"COLWRIT","description":"College Writing Programs"},"catalogNumber":{"prefix":"R","number":"4","suffix":"B","formatted":"R4B"},"displayName":"COLWRIT R4B","title":"Reading, Composition, and Research","transcriptTitle":"READ,COMP,RESEARCH","requisites":{"code":"000991","description":"R&amp;C Part B Prerequisite","formalDescription":"Must complete the First Half of the Reading &amp; Composition Requirement."}},"offeringNumber":1,"session":{"term":{"id":"2232","name":"2023 Spring"},"id":"1","name":"Regular Academic Session"},"number":"003","displayName":"2023 Spring COLWRIT R4B 003","allowedUnits":{"minimum":4,"maximum":4,"forAcademicProgress":4,"forFinancialAid":4},"gradingBasis":{"code":"GRD","description":"Graded"},"requirementDesignation":{"code":"RC2","description":"Reading and Composition B"}},"attributes":{"CCLV":[{"attribute":{"code":"CCLV","description":"CRSE LEVEL","formalDescription":"Academic Course Level"},"value":{"code":"UGLD","description":"UG Lower Division","formalDescription":"Undergraduate Lower Division Course"}}],"FLEX":[{"attribute":{"code":"FLEX","description":"FLEX","formalDescription":"Flexible Scheduling Approved"},"value":{"code":"FULLFLEX","description":"All Formats Regardless of Term","formalDescription":"Approved Flex Sched of all Formats for any Term"}}],"TIE":[{"attribute":{"code":"TIE","description":"Instr Type","formalDescription":"Instructional Activity Types"},"value":{"code":"SEMT","description":"Seminar-Topical","formalDescription":"Transmitting the Knowledge Base"}}],"VUOC":[{"attribute":{"code":"VUOC","description":"VCREDIT","formalDescription":"Variable Units of Credit"},"value":{"code":"F","description":"Fixed","formalDescription":"Fixed Unit 1 Value"}}],"NOTE":{"class-notes":{"attribute":{"code":"NOTE","formalDescription":"Class Notes"},"value":{"code":"2","formalDescription":"Enrollment is restricted to students who have satisfied the first half of the Reading and Composition requirement.  This course satisfies the second half of the Reading and Composition requirement."}},"special-title":{"attribute":{"code":"NOTE","formalDescription":"Special Title"},"value":{"code":"4","formalDescription":"The High Stakes in Sports Culture"}},"class-description":{"attribute":{"code":"NOTE","formalDescription":"Class Description"},"value":{"code":"6","formalDescription":"Don\u2019t worry, you don\u2019t necessarily have to be athletic to take this class- you don\u2019t even have to like sports (although you can)! Sports is based on ability and talent, but it can deviate, influenced by various social structures. Key questions guiding the course include: what is the role of sports in politics and activism? How is the culture of sports disneyfied and commercialized? Is sports journalism evolving? How do fans impact the culture? In this course, we\u2019ll explore this divergence in the culture of sports and its relationship with journalism, media, gentrification, body and fandom."}}}},"course":{"identifiers":[{"type":"cms-id","id":"354fc2b0-d2ac-420c-97ed-1f33b9f78ef1"},{"type":"cs-course-id","id":"104067"},{"type":"cms-version-independent-id","id":"bb35aa4e-7385-403d-803d-6fcc4770676b"}],"subjectArea":{"code":"COLWRIT","description":"College Writing Programs"},"catalogNumber":{"prefix":"R","number":"4","suffix":"B","formatted":"R4B"},"classSubjectArea":{"code":"COLWRIT","description":"College Writing Programs"},"displayName":"COLWRIT R4B","classDisplayName":"COLWRIT R4B","formerDisplayName":"","title":"Reading, Composition, and Research","transcriptTitle":"READ,COMP,RESEARCH ","description":"A lecture\/seminar satisfying the second half of the Reading &amp; Composition requirement, R4B offers structured and sustained practice in the processes used in reading, critical analysis, and writing. Students engage with thematically-related materials from a range of genres and media. In response, they craft short pieces leading to longer expository and\/or argumentative essays. Students develop a research question, draft a research essay, gather, evaluate, and synthesize information from various sources. Elements of the research process--a proposal, an annotated bibliography, an abstract, a works cited list, etc.--are submitted with the final report in a research portfolio. Students write a minimum of 32 pages of prose.\n","academicCareer":{"code":"UGRD","description":"Undergraduate"},"academicGroup":{"code":"CLS","description":"Clg of Letters &amp; Science"},"academicOrganization":{"code":"COLWRIT","description":"College Writing Programs"},"departmentNicknames":"COL WRIT!COLLEGE WRITING!CW!","primaryInstructionMethod":{"code":"SEM","description":"Student-instructor coverage of course materials"},"credit":{"type":"fixed","value":{"fixed":{"units":4}}},"gradingBasis":{"code":"graded","description":"graded"},"blindGrading":false,"status":{"code":"ACTIVE","description":"ACTIVE"},"fromDate":"2021-08-18","toDate":"2099-12-19","createdDate":"2021-03-30","updatedDate":"2021-04-23","printInCatalog":true,"printInstructors":true,"anyFeesExist":false,"finalExam":{"code":"N","description":"No final exam"},"instructorDropConsentRequired":false,"allowMultipleEnrollments":false,"spansMultipleTerms":false,"multipleTermNumber":0,"contactHours":7.5,"workloadHours":30,"tie":{"code":"SEMT","description":"SEMT"},"cip":{"code":"MISSINGcipCode","description":"MISSINGcipCode"},"hegis":{"code":"MISSINGhegisCode","description":"MISSINGhegisCode"},"repeatability":{"repeatable":false},"preparation":{"requiredText":"Previously passed an R_A course with a letter grade of C- or better.\nPreviously passed an articulated R_A course with a letter grade of C- or better.\nScore a 4 on the Advanced Placement Exam in English Literature and Composition.\nScore a 4 or 5 on the Advanced Placement Exam in English Language and Composition.\nScore of 5, 6, or 7 on the International Baccalaureate Higher Level Examination in English.","requiredCourses":[]},"creditRestriction":{"restrictionText":"","restrictionCourses":{"creditRestrictionCourses":[{"course":{"identifiers":[{"type":"cs-course-id","id":"104067"},{"type":"cms-version-independent-id","id":"bb35aa4e-7385-403d-803d-6fcc4770676b"}],"displayName":"COLWRIT R4B"},"maxCreditPercentage":100},{"course":{"identifiers":[{"type":"cs-course-id","id":"104067"},{"type":"cms-version-independent-id","id":"bb35aa4e-7385-403d-803d-6fcc4770676b"}],"displayName":"COLWRIT R4B"},"maxCreditPercentage":100}]}},"proposedInstructors":["Staff"],"formatsOffered":{"description":"One and one-half hours of lecture and one and one-half hours of seminar per week. Four hours of lecture and three and one-half hours of seminar per week for 6 weeks. Three hours of seminar\/discussion per week. ","formats":[{"termsAllowed":{"termNames":["Summer"]},"sessionType":"6","description":"3.5 hours of seminar and  4.0 hours of lecture per week","aggregateMinContactHours":7.5,"aggregateMaxContactHours":7.5,"minWorkloadHours":30,"maxWorkloadHours":30,"anyFeesExist":false,"components":[{"instructionMethod":{"code":"LEC","description":"Instructor presentation of course materials"},"primary":false,"minContactHours":4,"maxContactHours":4,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"WRK","description":"Outside Work Hours"},"primary":false,"minContactHours":22.5,"maxContactHours":22.5,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"SEM","description":"Student-instructor coverage of course materials"},"primary":true,"minContactHours":3.5,"maxContactHours":3.5,"finalExam":[],"feesExist":false}]},{"termsAllowed":{"termNames":["Fall"]},"sessionType":"15","description":"1.5 hours of seminar and  1.5 hours of lecture per week","aggregateMinContactHours":3,"aggregateMaxContactHours":3,"minWorkloadHours":12,"maxWorkloadHours":12,"anyFeesExist":false,"components":[{"instructionMethod":{"code":"SEM","description":"Student-instructor coverage of course materials"},"primary":true,"minContactHours":1.5,"maxContactHours":1.5,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"LEC","description":"Instructor presentation of course materials"},"primary":false,"minContactHours":1.5,"maxContactHours":1.5,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"WRK","description":"Outside Work Hours"},"primary":false,"minContactHours":9,"maxContactHours":9,"finalExam":[],"feesExist":false}]},{"termsAllowed":{"termNames":["Spring"]},"sessionType":"15","description":"1.5 hours of seminar and  1.5 hours of lecture per week","aggregateMinContactHours":3,"aggregateMaxContactHours":3,"minWorkloadHours":12,"maxWorkloadHours":12,"anyFeesExist":false,"components":[{"instructionMethod":{"code":"SEM","description":"Student-instructor coverage of course materials"},"primary":true,"minContactHours":1.5,"maxContactHours":1.5,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"LEC","description":"Instructor presentation of course materials"},"primary":false,"minContactHours":1.5,"maxContactHours":1.5,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"WRK","description":"Outside Work Hours"},"primary":false,"minContactHours":9,"maxContactHours":9,"finalExam":[],"feesExist":false}]}],"typicallyOffered":{"terms":{"termNames":["Summer","Fall","Spring"]},"comments":""},"summerOnly":false},"requirementsFulfilled":[{"code":"RC2","description":"Second half of the Reading and Composition Requirement"}]},"subjectName":"COLWRIT","resources":[]}' data-node='{"termName":"2023 Spring-1",
              "nid":"743547",
              "nodeURL":"/content/2023-spring-colwrit-r4b-003-sem-003",
              "nodeUpdated":"11/1/22, 12:12am",
              "deptLink":"http://writing.berkeley.edu/",
              "buildingURL":""}' data-term-details="{&quot;sessionDescription&quot;:&quot;Spring 2023&quot;,&quot;summerFees&quot;:&quot;&quot;,&quot;textbookInfo&quot;:&quot;See class syllabus or https:\/\/calstudentstore.berkeley.edu\/textbooks for the most current information.\r\n&lt;p&gt;&lt;a class='cc-button cc-small-button'  href=https:\/\/calstudentstore.berkeley.edu\/textbooks for the most current information.'&gt;Textbook Lookup&lt;\/a&gt;&lt;\/p&gt;\r\nGuide to Open, Free, &amp; Affordable Course Materials\r\n&lt;p&gt;&lt;a class='cc-button cc-small-button'  href=https:\/\/guides.lib.berkeley.edu\/affordable-resources&gt;eTextbooks&lt;\/a&gt;&lt;\/p&gt;&quot;,&quot;callToAction&quot;:&quot;&quot;,&quot;showFinalExamLocation&quot;:&quot;false&quot;,&quot;reservedSeatsInfo&quot;:null,&quot;enrollmentPhases&quot;:[{&quot;phase_name&quot;:&quot;Phase 1 for Continuing Students&quot;,&quot;phase_dates&quot;:{&quot;value&quot;:&quot;2022-10-17 00:00:00&quot;,&quot;value2&quot;:&quot;2022-11-06 00:00:00&quot;,&quot;timezone&quot;:&quot;America\/Los_Angeles&quot;,&quot;timezone_db&quot;:&quot;America\/Los_Angeles&quot;,&quot;date_type&quot;:&quot;datetime&quot;}},{&quot;phase_name&quot;:&quot;Phase 2 for Continuing Students&quot;,&quot;phase_dates&quot;:{&quot;value&quot;:&quot;2022-11-14 00:00:00&quot;,&quot;value2&quot;:&quot;2023-01-08 00:00:00&quot;,&quot;timezone&quot;:&quot;America\/Los_Angeles&quot;,&quot;timezone_db&quot;:&quot;America\/Los_Angeles&quot;,&quot;date_type&quot;:&quot;datetime&quot;}},{&quot;phase_name&quot;:&quot;Adjustment Period&quot;,&quot;phase_dates&quot;:{&quot;value&quot;:&quot;2023-01-09 00:00:00&quot;,&quot;value2&quot;:&quot;2023-03-24 00:00:00&quot;,&quot;timezone&quot;:&quot;America\/Los_Angeles&quot;,&quot;timezone_db&quot;:&quot;America\/Los_Angeles&quot;,&quot;date_type&quot;:&quot;datetime&quot;}},{&quot;phase_name&quot;:&quot;Phase 1 for New Undergraduate Students&quot;,&quot;phase_dates&quot;:{&quot;value&quot;:&quot;2022-11-08 00:00:00&quot;,&quot;value2&quot;:&quot;2023-01-08 00:00:00&quot;,&quot;timezone&quot;:&quot;America\/Los_Angeles&quot;,&quot;timezone_db&quot;:&quot;America\/Los_Angeles&quot;,&quot;date_type&quot;:&quot;datetime&quot;}}]}" id="">
<div  data-template="classFull"></div>
</div>]

`

I want to get only "minEnroll":0 this data but its very complicated. How can I get this. Should I use selenium

I tried using only BS4. Maybe I should use selenium but I dont want it

CodePudding user response:

Extract the value of the attribute data-enrollment and transform it with json.loads:

json.loads(soup.select_one('div.handlebarData').get('data-enrollment'))['available']['enrollmentStatus']['minEnroll']

Example

from bs4 import BeautifulSoup
import json

html='''
<div  data-enrollment='{"available":{"id":21313,"enrollmentStatus":{"status":{"code":"C","description":"Closed"},"enrolledCount":17,"reservedCount":0,"waitlistedCount":0,"minEnroll":0,"maxEnroll":17,"maxWaitlist":0,"openReserved":0}},"history":{"id":21313,"enrollmentStatus":{"status":{"code":"C","description":"Closed"},"enrolledCount":17,"reservedCount":0,"waitlistedCount":0,"minEnroll":0,"maxEnroll":17,"maxWaitlist":0,"openReserved":0}}}' data-image='{"imagePath":"/sites/default/files/styles/xlarge/public/COLWRIT-18-2.jpeg","uri":"public://COLWRIT-18-2.jpeg"}' data-json='{"id":21313,"number":"003","component":{"code":"SEM","description":"Seminar"},"displayName":"2023 Spring COLWRIT R4B 003 SEM 003","instructionMode":{"code":"P","description":"In-Person Instruction"},"type":{"code":"E","description":"Enrollment","formalDescription":"Enrollment Section"},"academicOrganization":{"code":"COLWRIT","description":"College Writing Programs","formalDescription":"College Writing Programs"},"academicGroup":{"code":"CLS","description":"L&amp;S","formalDescription":"College of Letters and Science"},"startDate":"2023-01-17","endDate":"2023-05-05","status":{"code":"A","description":"Active"},"association":{"primary":true,"primaryAssociatedComponent":{"code":"SEM","description":"Seminar"},"primaryAssociatedSectionId":21313,"primaryAssociatedSectionIds":[21313],"associatedClass":3},"enrollmentStatus":{"status":{"code":"C","description":"Closed"},"enrolledCount":17,"reservedCount":0,"waitlistedCount":0,"minEnroll":0,"maxEnroll":17,"maxWaitlist":0,"openReserved":0},"printInScheduleOfClasses":true,"addConsentRequired":{"code":"N","description":"No Special Consent Required"},"dropConsentRequired":{"code":"N","description":"No Special Consent Required"},"graded":true,"feesExist":false,"roomShare":false,"sectionAttributes":[{"attribute":{"code":"CCLV","description":"CRSE LEVEL","formalDescription":"Academic Course Level"},"value":{"code":"UGLD","description":"UG Lower Division","formalDescription":"Undergraduate Lower Division Course"}},{"attribute":{"code":"FLEX","description":"FLEX","formalDescription":"Flexible Scheduling Approved"},"value":{"code":"FULLFLEX","description":"All Formats Regardless of Term","formalDescription":"Approved Flex Sched of all Formats for any Term"}},{"attribute":{"code":"TIE","description":"Instr Type","formalDescription":"Instructional Activity Types"},"value":{"code":"SEMT","description":"Seminar-Topical","formalDescription":"Transmitting the Knowledge Base"}},{"attribute":{"code":"VUOC","description":"VCREDIT","formalDescription":"Variable Units of Credit"},"value":{"code":"F","description":"Fixed","formalDescription":"Fixed Unit 1 Value"}},{"attribute":{"code":"NOTE","formalDescription":"Class Notes"},"value":{"code":"2","formalDescription":"Enrollment is restricted to students who have satisfied the first half of the Reading and Composition requirement.  This course satisfies the second half of the Reading and Composition requirement."}},{"attribute":{"code":"NOTE","formalDescription":"Special Title"},"value":{"code":"4","formalDescription":"The High Stakes in Sports Culture"}},{"attribute":{"code":"NOTE","formalDescription":"Class Description"},"value":{"code":"6","formalDescription":"Don\u2019t worry, you don\u2019t necessarily have to be athletic to take this class- you don\u2019t even have to like sports (although you can)! Sports is based on ability and talent, but it can deviate, influenced by various social structures. Key questions guiding the course include: what is the role of sports in politics and activism? How is the culture of sports disneyfied and commercialized? Is sports journalism evolving? How do fans impact the culture? In this course, we\u2019ll explore this divergence in the culture of sports and its relationship with journalism, media, gentrification, body and fandom."}}],"roomCharacteristics":[{"code":"04","description":"AV-Computer Data Display","quantity":1},{"code":"09","description":"AV-DVD Player","quantity":1},{"code":"51","description":"Seating-Movable Desks","quantity":1}],"meetings":[{"number":1,"meetsDays":"MoWeFr","meetsMonday":true,"meetsTuesday":false,"meetsWednesday":true,"meetsThursday":false,"meetsFriday":true,"meetsSaturday":false,"meetsSunday":false,"startTime":"11:00:00","endTime":"11:59:00","location":{"code":"SOCS118","description":"Social Sciences Building 118"},"building":{"code":"1761","description":"Social Sci"},"assignedInstructors":[{"assignmentNumber":1,"instructor":{"identifiers":[{"type":"campus-uid","id":"972764","disclose":true}],"names":[{"type":{"code":"FRM","description":"Former"},"familyName":"Asakawa","givenName":"Chisako","formattedName":"Chisako  Asakawa","disclose":false,"uiControl":{"code":"N","description":"Do Not Display"},"fromDate":"2014-07-07"},{"type":{"code":"PRF","description":"Preferred"},"familyName":"Cole","givenName":"Chisako","formattedName":"Chisako A Cole","disclose":true,"uiControl":{"code":"U","description":"Edit - No Delete"},"fromDate":"2020-06-08"},{"type":{"code":"PRI","description":"Primary"},"familyName":"Cole","givenName":"Chisako","formattedName":"Chisako A Cole","disclose":true,"uiControl":{"code":"D","description":"Display Only"},"fromDate":"2020-06-08"}]},"role":{"code":"PI","description":"1-TIC","formalDescription":"Teaching and In Charge"},"contactMinutes":0,"printInScheduleOfClasses":true,"gradeRosterAccess":{"code":"A","description":"Approve","formalDescription":"Approve"}}],"startDate":"2023-01-17","endDate":"2023-05-05","meetingTopic":[]}],"class":{"course":{"identifiers":[{"type":"cs-course-id","id":"104067"}],"subjectArea":{"code":"COLWRIT","description":"College Writing Programs"},"catalogNumber":{"prefix":"R","number":"4","suffix":"B","formatted":"R4B"},"displayName":"COLWRIT R4B","title":"Reading, Composition, and Research","transcriptTitle":"READ,COMP,RESEARCH","requisites":{"code":"000991","description":"R&amp;C Part B Prerequisite","formalDescription":"Must complete the First Half of the Reading &amp; Composition Requirement."}},"offeringNumber":1,"session":{"term":{"id":"2232","name":"2023 Spring"},"id":"1","name":"Regular Academic Session"},"number":"003","displayName":"2023 Spring COLWRIT R4B 003","allowedUnits":{"minimum":4,"maximum":4,"forAcademicProgress":4,"forFinancialAid":4},"gradingBasis":{"code":"GRD","description":"Graded"},"requirementDesignation":{"code":"RC2","description":"Reading and Composition B"}},"attributes":{"CCLV":[{"attribute":{"code":"CCLV","description":"CRSE LEVEL","formalDescription":"Academic Course Level"},"value":{"code":"UGLD","description":"UG Lower Division","formalDescription":"Undergraduate Lower Division Course"}}],"FLEX":[{"attribute":{"code":"FLEX","description":"FLEX","formalDescription":"Flexible Scheduling Approved"},"value":{"code":"FULLFLEX","description":"All Formats Regardless of Term","formalDescription":"Approved Flex Sched of all Formats for any Term"}}],"TIE":[{"attribute":{"code":"TIE","description":"Instr Type","formalDescription":"Instructional Activity Types"},"value":{"code":"SEMT","description":"Seminar-Topical","formalDescription":"Transmitting the Knowledge Base"}}],"VUOC":[{"attribute":{"code":"VUOC","description":"VCREDIT","formalDescription":"Variable Units of Credit"},"value":{"code":"F","description":"Fixed","formalDescription":"Fixed Unit 1 Value"}}],"NOTE":{"class-notes":{"attribute":{"code":"NOTE","formalDescription":"Class Notes"},"value":{"code":"2","formalDescription":"Enrollment is restricted to students who have satisfied the first half of the Reading and Composition requirement.  This course satisfies the second half of the Reading and Composition requirement."}},"special-title":{"attribute":{"code":"NOTE","formalDescription":"Special Title"},"value":{"code":"4","formalDescription":"The High Stakes in Sports Culture"}},"class-description":{"attribute":{"code":"NOTE","formalDescription":"Class Description"},"value":{"code":"6","formalDescription":"Don\u2019t worry, you don\u2019t necessarily have to be athletic to take this class- you don\u2019t even have to like sports (although you can)! Sports is based on ability and talent, but it can deviate, influenced by various social structures. Key questions guiding the course include: what is the role of sports in politics and activism? How is the culture of sports disneyfied and commercialized? Is sports journalism evolving? How do fans impact the culture? In this course, we\u2019ll explore this divergence in the culture of sports and its relationship with journalism, media, gentrification, body and fandom."}}}},"course":{"identifiers":[{"type":"cms-id","id":"354fc2b0-d2ac-420c-97ed-1f33b9f78ef1"},{"type":"cs-course-id","id":"104067"},{"type":"cms-version-independent-id","id":"bb35aa4e-7385-403d-803d-6fcc4770676b"}],"subjectArea":{"code":"COLWRIT","description":"College Writing Programs"},"catalogNumber":{"prefix":"R","number":"4","suffix":"B","formatted":"R4B"},"classSubjectArea":{"code":"COLWRIT","description":"College Writing Programs"},"displayName":"COLWRIT R4B","classDisplayName":"COLWRIT R4B","formerDisplayName":"","title":"Reading, Composition, and Research","transcriptTitle":"READ,COMP,RESEARCH ","description":"A lecture\/seminar satisfying the second half of the Reading &amp; Composition requirement, R4B offers structured and sustained practice in the processes used in reading, critical analysis, and writing. Students engage with thematically-related materials from a range of genres and media. In response, they craft short pieces leading to longer expository and\/or argumentative essays. Students develop a research question, draft a research essay, gather, evaluate, and synthesize information from various sources. Elements of the research process--a proposal, an annotated bibliography, an abstract, a works cited list, etc.--are submitted with the final report in a research portfolio. Students write a minimum of 32 pages of prose.\n","academicCareer":{"code":"UGRD","description":"Undergraduate"},"academicGroup":{"code":"CLS","description":"Clg of Letters &amp; Science"},"academicOrganization":{"code":"COLWRIT","description":"College Writing Programs"},"departmentNicknames":"COL WRIT!COLLEGE WRITING!CW!","primaryInstructionMethod":{"code":"SEM","description":"Student-instructor coverage of course materials"},"credit":{"type":"fixed","value":{"fixed":{"units":4}}},"gradingBasis":{"code":"graded","description":"graded"},"blindGrading":false,"status":{"code":"ACTIVE","description":"ACTIVE"},"fromDate":"2021-08-18","toDate":"2099-12-19","createdDate":"2021-03-30","updatedDate":"2021-04-23","printInCatalog":true,"printInstructors":true,"anyFeesExist":false,"finalExam":{"code":"N","description":"No final exam"},"instructorDropConsentRequired":false,"allowMultipleEnrollments":false,"spansMultipleTerms":false,"multipleTermNumber":0,"contactHours":7.5,"workloadHours":30,"tie":{"code":"SEMT","description":"SEMT"},"cip":{"code":"MISSINGcipCode","description":"MISSINGcipCode"},"hegis":{"code":"MISSINGhegisCode","description":"MISSINGhegisCode"},"repeatability":{"repeatable":false},"preparation":{"requiredText":"Previously passed an R_A course with a letter grade of C- or better.\nPreviously passed an articulated R_A course with a letter grade of C- or better.\nScore a 4 on the Advanced Placement Exam in English Literature and Composition.\nScore a 4 or 5 on the Advanced Placement Exam in English Language and Composition.\nScore of 5, 6, or 7 on the International Baccalaureate Higher Level Examination in English.","requiredCourses":[]},"creditRestriction":{"restrictionText":"","restrictionCourses":{"creditRestrictionCourses":[{"course":{"identifiers":[{"type":"cs-course-id","id":"104067"},{"type":"cms-version-independent-id","id":"bb35aa4e-7385-403d-803d-6fcc4770676b"}],"displayName":"COLWRIT R4B"},"maxCreditPercentage":100},{"course":{"identifiers":[{"type":"cs-course-id","id":"104067"},{"type":"cms-version-independent-id","id":"bb35aa4e-7385-403d-803d-6fcc4770676b"}],"displayName":"COLWRIT R4B"},"maxCreditPercentage":100}]}},"proposedInstructors":["Staff"],"formatsOffered":{"description":"One and one-half hours of lecture and one and one-half hours of seminar per week. Four hours of lecture and three and one-half hours of seminar per week for 6 weeks. Three hours of seminar\/discussion per week. ","formats":[{"termsAllowed":{"termNames":["Summer"]},"sessionType":"6","description":"3.5 hours of seminar and  4.0 hours of lecture per week","aggregateMinContactHours":7.5,"aggregateMaxContactHours":7.5,"minWorkloadHours":30,"maxWorkloadHours":30,"anyFeesExist":false,"components":[{"instructionMethod":{"code":"LEC","description":"Instructor presentation of course materials"},"primary":false,"minContactHours":4,"maxContactHours":4,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"WRK","description":"Outside Work Hours"},"primary":false,"minContactHours":22.5,"maxContactHours":22.5,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"SEM","description":"Student-instructor coverage of course materials"},"primary":true,"minContactHours":3.5,"maxContactHours":3.5,"finalExam":[],"feesExist":false}]},{"termsAllowed":{"termNames":["Fall"]},"sessionType":"15","description":"1.5 hours of seminar and  1.5 hours of lecture per week","aggregateMinContactHours":3,"aggregateMaxContactHours":3,"minWorkloadHours":12,"maxWorkloadHours":12,"anyFeesExist":false,"components":[{"instructionMethod":{"code":"SEM","description":"Student-instructor coverage of course materials"},"primary":true,"minContactHours":1.5,"maxContactHours":1.5,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"LEC","description":"Instructor presentation of course materials"},"primary":false,"minContactHours":1.5,"maxContactHours":1.5,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"WRK","description":"Outside Work Hours"},"primary":false,"minContactHours":9,"maxContactHours":9,"finalExam":[],"feesExist":false}]},{"termsAllowed":{"termNames":["Spring"]},"sessionType":"15","description":"1.5 hours of seminar and  1.5 hours of lecture per week","aggregateMinContactHours":3,"aggregateMaxContactHours":3,"minWorkloadHours":12,"maxWorkloadHours":12,"anyFeesExist":false,"components":[{"instructionMethod":{"code":"SEM","description":"Student-instructor coverage of course materials"},"primary":true,"minContactHours":1.5,"maxContactHours":1.5,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"LEC","description":"Instructor presentation of course materials"},"primary":false,"minContactHours":1.5,"maxContactHours":1.5,"finalExam":[],"feesExist":false},{"instructionMethod":{"code":"WRK","description":"Outside Work Hours"},"primary":false,"minContactHours":9,"maxContactHours":9,"finalExam":[],"feesExist":false}]}],"typicallyOffered":{"terms":{"termNames":["Summer","Fall","Spring"]},"comments":""},"summerOnly":false},"requirementsFulfilled":[{"code":"RC2","description":"Second half of the Reading and Composition Requirement"}]},"subjectName":"COLWRIT","resources":[]}' data-node='{"termName":"2023 Spring-1",
              "nid":"743547",
              "nodeURL":"/content/2023-spring-colwrit-r4b-003-sem-003",
              "nodeUpdated":"11/1/22, 12:12am",
              "deptLink":"http://writing.berkeley.edu/",
              "buildingURL":""}' data-term-details="{&quot;sessionDescription&quot;:&quot;Spring 2023&quot;,&quot;summerFees&quot;:&quot;&quot;,&quot;textbookInfo&quot;:&quot;See class syllabus or https:\/\/calstudentstore.berkeley.edu\/textbooks for the most current information.\r\n&lt;p&gt;&lt;a class='cc-button cc-small-button'  href=https:\/\/calstudentstore.berkeley.edu\/textbooks for the most current information.'&gt;Textbook Lookup&lt;\/a&gt;&lt;\/p&gt;\r\nGuide to Open, Free, &amp; Affordable Course Materials\r\n&lt;p&gt;&lt;a class='cc-button cc-small-button'  href=https:\/\/guides.lib.berkeley.edu\/affordable-resources&gt;eTextbooks&lt;\/a&gt;&lt;\/p&gt;&quot;,&quot;callToAction&quot;:&quot;&quot;,&quot;showFinalExamLocation&quot;:&quot;false&quot;,&quot;reservedSeatsInfo&quot;:null,&quot;enrollmentPhases&quot;:[{&quot;phase_name&quot;:&quot;Phase 1 for Continuing Students&quot;,&quot;phase_dates&quot;:{&quot;value&quot;:&quot;2022-10-17 00:00:00&quot;,&quot;value2&quot;:&quot;2022-11-06 00:00:00&quot;,&quot;timezone&quot;:&quot;America\/Los_Angeles&quot;,&quot;timezone_db&quot;:&quot;America\/Los_Angeles&quot;,&quot;date_type&quot;:&quot;datetime&quot;}},{&quot;phase_name&quot;:&quot;Phase 2 for Continuing Students&quot;,&quot;phase_dates&quot;:{&quot;value&quot;:&quot;2022-11-14 00:00:00&quot;,&quot;value2&quot;:&quot;2023-01-08 00:00:00&quot;,&quot;timezone&quot;:&quot;America\/Los_Angeles&quot;,&quot;timezone_db&quot;:&quot;America\/Los_Angeles&quot;,&quot;date_type&quot;:&quot;datetime&quot;}},{&quot;phase_name&quot;:&quot;Adjustment Period&quot;,&quot;phase_dates&quot;:{&quot;value&quot;:&quot;2023-01-09 00:00:00&quot;,&quot;value2&quot;:&quot;2023-03-24 00:00:00&quot;,&quot;timezone&quot;:&quot;America\/Los_Angeles&quot;,&quot;timezone_db&quot;:&quot;America\/Los_Angeles&quot;,&quot;date_type&quot;:&quot;datetime&quot;}},{&quot;phase_name&quot;:&quot;Phase 1 for New Undergraduate Students&quot;,&quot;phase_dates&quot;:{&quot;value&quot;:&quot;2022-11-08 00:00:00&quot;,&quot;value2&quot;:&quot;2023-01-08 00:00:00&quot;,&quot;timezone&quot;:&quot;America\/Los_Angeles&quot;,&quot;timezone_db&quot;:&quot;America\/Los_Angeles&quot;,&quot;date_type&quot;:&quot;datetime&quot;}}]}" id="">
<div  data-template="classFull"></div>
</div>
'''

soup = BeautifulSoup(html)

json.loads(soup.select_one('div.handlebarData').get('data-enrollment'))['available']['enrollmentStatus']['minEnroll']

CodePudding user response:

I think you just need to look through your div attributes with BS4.

Take a look at this similar issue. BeautifulSoup extract data within a div

Since your data is nested in "data-enrollment" you will likely need to perform a secondary search once you extract the data from that attribute using by converting to a dictionary or just using some regex.
  • Related