,,,, ich will aus einer Seite Texte beziehen: Hier stoße ich auf zwei Probleme.
a. zunächst hab ich die Frage, wie ich über eine ganze Reihe von URLs itteriere und
b. gelingt es mir nicht auf Anhieb, den Text einer Klasse zurückzubekommen...
ich beginne mit einigen ersten Schritten: ... die auch gut gelingen.
a. für einen ersten Test fange ich an, die Überschriften zu holen:_
Code: Alles auswählen
# Python program to print all heading tags
import requests
from bs4 import BeautifulSoup
# scraping a the content
url_link = 'https://s3platform-legacy.jrc.ec.europa.eu/digital-innovation-hubs-tool/-/dih/1096/view'
request = requests.get(url_link)
Soup = BeautifulSoup(request.text, 'lxml')
# creating a list of all common heading tags
heading_tags = ["h1", "h2", "h3", "h4"]
for tags in Soup.find_all(heading_tags):
print(tags.name + ' -> ' + tags.text.strip())
Das gibt mir einen ersten Überblick
h1 -> Smart Specialisation Platform
h1 -> Digital Innovation Hubs
Digital Innovation Hubs
h2 -> Bavarian Robotic Network (BaRoN) Bayerisches Robotik-Netzwerk, BaRoN
h4 -> Contact Data
h4 -> Description
h4 -> Link to national or regional initiatives for digitising industry
h4 -> Market and Services
h4 -> Organization
h4 -> Evolutionary Stage
h4 -> Geographical Scope
h4 -> Funding
h4 -> Partners
h4 -> Technologies
soweit - so gut: was ich noch vorhabe, das ist nun, den Content der h4 Tags beziehen:
Also ich bin relativ neu in BS4 und pandas: ich will itterieren
ich will über eine Reihe von Seiten itterieren mit BS4 : https://s3platform.jrc.ec.europa.eu/dig ... -hubs-tool
hier haben wir die folgenden URLs . circa 700 verschiedene. Da stellt sich die Frage wie ich diese alle abfrage:
https://s3platform-legacy.jrc.ec.europa ... /1096/view
https://s3platform-legacy.jrc.ec.europa ... 17865/view
https://s3platform-legacy.jrc.ec.europa ... /1416/view
auf jeder dieser Seiten hab ich diverse Elemente die ich brauche:
so zum Beispiel:
Code: Alles auswählen
dif hubCardTitle
dif hubCardContent
<div class="hubCardContent" id="yui_patched_v3_11_0_1_1650793691535_463">
<p class="infoLabel">Description</p>
<p> </p><p></p>
</div>
nun - soweit ich informiert bin, brauch ich nicht soup.find_all wenn ich nlediglich ein Element suche, soup.find würde auch so funktionieren man kann das auch so ansetzen: tag.string/tag.contents/tag.text to um den Text zu erhalten.(vgl ²
Code: Alles auswählen
# Python program to print all heading tags
import requests
from bs4 import BeautifulSoup
# Fetch the page and create a Beautiful Soup object
page = requests.get("https://s3platform-legacy.jrc.ec.europa.eu/digital-innovation-hubs-tool/-/dih/1096/view")
soup = BeautifulSoup(page.text, "lxml")
div = soup.find('div', {"class" : hubCardContent})
text = div.string
a. dif hubCardTitle
b. dif hubCardContent
hier muss ich nochmals weiter überlegen.
zu ² vgl. Web scraping - Get text from a class with BeautifulSoup and Python?
https://stackoverflow.com/questions/454 ... and-python