
Ich versuche im Moment mittels BS4 u. requests Folgendes zu erreichen. aus einer Seite mit vielen (gleichen) Links diese zu jeweils zu öffnen und ein kleinen Datensatz auf der Subseite zu lesen.
Also das Beispiel ist hier dieses ( nur um einfach mal das prinzipiell durchzuspielen - die (se) Seite ist im Grunde nicht wichtig.
Ziel: Failed Bank List: Die Liste beinhaltet Banken die gescheitert /(failed) sind seit Oktober 2000.
URL: https://www.fdic.gov/resources/resoluti ... bank-list/
Plan: ich hole die Links aus der Basis-Seite und schreibe Sie in ein array.
Darüber hinaus: ich will die (se) Links holen und öffnen und eine Kleine Information (immer aus der Subseite holen)
mein momentaner Ansatz: also zur Aufgabe des wiederholten (immergleichen) Holen, bzw. Öffnen eines Links der Zielseite gehe ich wie folgt vor
Setup: Anaconda auf Win 10 mit Python 3.8.5 und BS4 (version 4.8.2)
Code: Alles auswählen
from bs4 import BeautifulSoup
import requests
import re
def getLinks(url):
r = requests.get("https://www.fdic.gov/resources/resolutions/bank-failures/failed-bank-list/")
soup = BeautifulSoup(r.content)
links = []
for link in soup.findAll('a', attrs={'href': re.compile("^http://")}):
links.append(link.get('href'))
##It will scrape all the a tags, and for each a tags, it will append the href attribute to the links list.
return links
print( getLinks("https://www.fdic.gov/resources/resolutions/bank-failures/failed-bank-list/") )
that contains the following pages that hold information about the towns with inhabitants:
das Datenset: ... bestehen aus Links - ( das sind also alles Links in dem folgenden Block ) - die jeweils geöffnet werden sollen ...
Gesamtziel: Aus den sub-pages sollte ein (immergleicher) kleiner Datensatz gewonnen werden.Almena State Bank
First City Bank of Florida
The First State Bank
Ericson State Bank
City National Bank of New Jersey
Resolute Bank Maumee
Louisa Community Bank
The Enloe State Bank
Also muss ich durch die subpages durch gehen
https://www.fdic.gov/resources/resoluti ... state.html
https://www.fdic.gov/resources/resoluti ... ybank.html
https://www.fdic.gov/resources/resoluti ... sb-wv.html
und so fort:
im Moment. habe ich den Fehler: /error
Code: Alles auswählen
ModuleNotFoundError: No module named 'BeautifulSoup'
obwohl ich folgende Version von BS4 habe: BeautifulSoup4 Version 4.8.2
Wenn ich das Problem gelöst haben werde, dann kann ich mich der Skriptlogik zuwenden und sehen, wie ich
a. die Subseiten jeweils öffne und
b. dann hier jeweils ein kl. Information herausholen - der im Grunde an der immerglichen Stelle ist - und den ich über einen CSS-Selektor gut definiert habe.
Ein Beispiel: cf: https://www.fdic.gov/resources/resoluti ... ybank.html
die in diesem tag: (wie gesagt, das ganze ist einfach : denn es ist diese Stelle - die auf allen Subseiten interessiert - mit diesem Selektor "<div class="usa-layout desktop:grid-col-12">"Failed Bank Information for First City Bank of Florida, Fort Walton Beach, FL
On Friday, October 16, 2020, First City Bank of Florida was closed by the Florida Office of Financial Regulation. The FDIC was named Receiver. No advance notice is given to the public when a financial institution is closed. United Fidelity Bank, fsb, Evansville, IN acquired all deposit accounts and substantially all the assets. All shares of stock were owned by the holding company, which was not involved in this transaction.
Code: Alles auswählen
<div class="usa-layout desktop:grid-col-12">
<p class="fbankcategory">Failed Bank List</p>
<!-- don't touch -->
<!--Failed Bank Title-->
<h1 class="fbanktitle">Failed Bank Information for First City Bank of Florida, Fort Walton Beach, FL</h1>
<!-- update -->
<div class="fbankgrayborder"></div>
<!-- don't touch -->
<p class="fbankdescription"><!-- update -->
On Friday, October 16, 2020, First City Bank of Florida was closed by the Florida Office of Financial Regulation. The FDIC was named Receiver. No advance notice is given to the public when a financial institution is closed. United Fidelity Bank, fsb, Evansville, IN acquired all deposit accounts and substantially all the assets. All shares of stock were owned by the holding company, which was not involved in this transaction.</p>
</div>
Was mir an diesem Beispiel also (und das ist in der Tat ein Beispiel - an dem ich praktisch übe wie man so etwas macht -
-a. die Links auf der Basis-Seite öffnen und dann
-b. auf der Subseite in einer kl. Tabelle (ggf mit Panda) einen Text auszulesen..
...im Moment aber muss ich erstmal den Error hier beheben
Code: Alles auswählen
ModuleNotFoundError: No module named 'BeautifulSoup'
Danach kann ich mich den anderen Themen zuwenden!
Viele Grüße Say
