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&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&C Part B Prerequisite","formalDescription":"Must complete the First Half of the Reading & 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 & 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 & 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="{"sessionDescription":"Spring 2023","summerFees":"","textbookInfo":"See class syllabus or https:\/\/calstudentstore.berkeley.edu\/textbooks for the most current information.\r\n<p><a class='cc-button cc-small-button' href=https:\/\/calstudentstore.berkeley.edu\/textbooks for the most current information.'>Textbook Lookup<\/a><\/p>\r\nGuide to Open, Free, & Affordable Course Materials\r\n<p><a class='cc-button cc-small-button' href=https:\/\/guides.lib.berkeley.edu\/affordable-resources>eTextbooks<\/a><\/p>","callToAction":"","showFinalExamLocation":"false","reservedSeatsInfo":null,"enrollmentPhases":[{"phase_name":"Phase 1 for Continuing Students","phase_dates":{"value":"2022-10-17 00:00:00","value2":"2022-11-06 00:00:00","timezone":"America\/Los_Angeles","timezone_db":"America\/Los_Angeles","date_type":"datetime"}},{"phase_name":"Phase 2 for Continuing Students","phase_dates":{"value":"2022-11-14 00:00:00","value2":"2023-01-08 00:00:00","timezone":"America\/Los_Angeles","timezone_db":"America\/Los_Angeles","date_type":"datetime"}},{"phase_name":"Adjustment Period","phase_dates":{"value":"2023-01-09 00:00:00","value2":"2023-03-24 00:00:00","timezone":"America\/Los_Angeles","timezone_db":"America\/Los_Angeles","date_type":"datetime"}},{"phase_name":"Phase 1 for New Undergraduate Students","phase_dates":{"value":"2022-11-08 00:00:00","value2":"2023-01-08 00:00:00","timezone":"America\/Los_Angeles","timezone_db":"America\/Los_Angeles","date_type":"datetime"}}]}" 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&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&C Part B Prerequisite","formalDescription":"Must complete the First Half of the Reading & 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 & 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 & 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="{"sessionDescription":"Spring 2023","summerFees":"","textbookInfo":"See class syllabus or https:\/\/calstudentstore.berkeley.edu\/textbooks for the most current information.\r\n<p><a class='cc-button cc-small-button' href=https:\/\/calstudentstore.berkeley.edu\/textbooks for the most current information.'>Textbook Lookup<\/a><\/p>\r\nGuide to Open, Free, & Affordable Course Materials\r\n<p><a class='cc-button cc-small-button' href=https:\/\/guides.lib.berkeley.edu\/affordable-resources>eTextbooks<\/a><\/p>","callToAction":"","showFinalExamLocation":"false","reservedSeatsInfo":null,"enrollmentPhases":[{"phase_name":"Phase 1 for Continuing Students","phase_dates":{"value":"2022-10-17 00:00:00","value2":"2022-11-06 00:00:00","timezone":"America\/Los_Angeles","timezone_db":"America\/Los_Angeles","date_type":"datetime"}},{"phase_name":"Phase 2 for Continuing Students","phase_dates":{"value":"2022-11-14 00:00:00","value2":"2023-01-08 00:00:00","timezone":"America\/Los_Angeles","timezone_db":"America\/Los_Angeles","date_type":"datetime"}},{"phase_name":"Adjustment Period","phase_dates":{"value":"2023-01-09 00:00:00","value2":"2023-03-24 00:00:00","timezone":"America\/Los_Angeles","timezone_db":"America\/Los_Angeles","date_type":"datetime"}},{"phase_name":"Phase 1 for New Undergraduate Students","phase_dates":{"value":"2022-11-08 00:00:00","value2":"2023-01-08 00:00:00","timezone":"America\/Los_Angeles","timezone_db":"America\/Los_Angeles","date_type":"datetime"}}]}" 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.