ich folgenden Pandas Datenrahmen erhalten mag:Extract mehr Klasse in Pandas Datenrahmen unter Verwendung Schöne Suppe
Hier ist alles, was ich versuchte, hätte versucht, die Klasse übergibt, sondern alle Inhalte bereitstellt und Nicht das Getrennte, wie ich es mir ansehe. Ich bin neu bei BS4.
html_doc = """
<div class="schoolinfo" data-attr-lat="33.7527" data-attr-lon="-84.3867" id="1396">
<div class="schoolheader">
<h3 class="schoolname">
Georgia State University
</h3>
</div>
<div class="schooldetails">
<div class="schoollocation">
<div class="citystate">
Atlanta, Georgia
</div>
</div>
<div class="programs">
<div class="schoolprogram">
<h4>
<a href="http://cs.gsu.edu/graduate/doctor-philosophy/ph-d-bioinformatics-concentration-degree-requirements/" target="_blank">
Ph.D. in Computer Science - Bioinformatics Concentration
</a>
</h4>
<div class="cost-curric">
<a class="btn btn-sm btn-default detailbutton" href="http://cs.gsu.edu/graduate/doctor-philosophy/ph-d-admission-requirements/" target="_blank">
HOW TO APPLY
</a>
<a class="btn btn-sm btn-default detailbutton" href="https://catalog.gsu.edu/graduate20152016/computer-science/" target="_blank">
CURRICULUM
</a>
<a class="btn btn-sm btn-default detailbutton" href="http://sfs.gsu.edu/tuition-fees/what-it-costs/tuition-and-fees/" target="_blank">
COST
</a>
</div>
<div class="programdetails">
<div class="dept">
<strong>
OFFERED BY:
</strong>
Department of Computer Science
</div>
<div class="dept">
<strong>
DELIVERY:
</strong>
Campus
</div>
<div class="dept">
<strong>
LENGTH:
</strong>
48 Credits
</div>
<div class="dept">
<strong>
PRE-REQUISITE TECHNICAL COURSEWORK:
</strong>
technical bachelor's degree
</div>
</div>
</div>
</div>
</div>
</div>
"""
soup = BeautifulSoup(html_doc, 'html.parser')
print(soup.prettify())
for i in soup.find_all(attrs={'class': ["schoolname", "citystate", "schoolprogram","dept"]}):
print(i)
Hat die gewünschten Variablen nicht zur Verfügung stellen und alle HTML-Inhalte ohne Filterung passieren, wenn ich nur 1 Klasse übergeben, als ich erforderliche Tag erhalten, aber keine Liste von Tags ... hier ist der Ausgang des find_all mit mehreren "Klasse"
<h3 class="schoolname">
Georgia State University
</h3>
<div class="citystate">
Atlanta, Georgia
</div>
<div class="schoolprogram">
<h4>
<a href="http://cs.gsu.edu/graduate/doctor-philosophy/ph-d-bioinformatics-concentration-degree-requirements/" target="_blank">
Ph.D. in Computer Science - Bioinformatics Concentration
</a>
</h4>
<div class="cost-curric">
<a class="btn btn-sm btn-default detailbutton" href="http://cs.gsu.edu/graduate/doctor-philosophy/ph-d-admission-requirements/" target="_blank">
HOW TO APPLY
</a>
<a class="btn btn-sm btn-default detailbutton" href="https://catalog.gsu.edu/graduate20152016/computer-science/" target="_blank">
CURRICULUM
</a>
<a class="btn btn-sm btn-default detailbutton" href="http://sfs.gsu.edu/tuition-fees/what-it-costs/tuition-and-fees/" target="_blank">
COST
</a>
</div>
<div class="programdetails">
<div class="dept">
<strong>
OFFERED BY:
</strong>
Department of Computer Science
</div>
<div class="dept">
<strong>
DELIVERY:
</strong>
Campus
</div>
<div class="dept">
<strong>
LENGTH:
</strong>
48 Credits
</div>
<div class="dept">
<strong>
PRE-REQUISITE TECHNICAL COURSEWORK:
</strong>
technical bachelor's degree
</div>
</div>
</div>
<div class="dept">
<strong>
OFFERED BY:
</strong>
Department of Computer Science
</div>
<div class="dept">
<strong>
DELIVERY:
</strong>
Campus
</div>
<div class="dept">
<strong>
LENGTH:
</strong>
48 Credits
</div>
<div class="dept">
<strong>
PRE-REQUISITE TECHNICAL COURSEWORK:
</strong>
technical bachelor's degree
</div>
-Code für mehrere:
pathP = "http://www.mastersindatascience.org/schools/doctorate/#on-campus" #text for multiple
response = requests.get(pathP)
response.text[:100] # Access the HTML with the text property
soup = BeautifulSoup(response.text, "lxml")
für mehrere: dept = [x.text.strip() für x in soup.find_all ('div', {'class': 'dept'})] #wie funktioniert der strip bitte? Abt = Abt [Abt.Index (':') + 1:] .Streifen(). #Vielen Dank . ValueError: ':' ist nicht in der Liste –
zuerst 'dept = [x.text() für x in soup.find_all ('div', {'class': 'dept'})]] und dann ' dept = [ x [x.index (':') + 1:]. strip() für x in dept] '--- Wenn meine Antwort hilfreich ist, denken Sie bitte daran, [accept/upvote] (https: //meta.stackexchange. com/a/5235) die Antwort, es ist insgesamt ein gutes für die Gemeinschaft. –
dept = [x [x.index (':') + 1:]. Strip() für x in dept] # extrahiert nur Position 1 Element aus der Liste, muss einen Weg finden, um aus zu extrahieren: ANGEBOTEN VON: Computer Science Department und LIEFERUNG: Online –