Advertisement
DeaD_EyE

bundestag abstimmungen

May 19th, 2023
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. from enum import StrEnum
  2. from urllib.parse import urlencode
  3. from urllib.request import urlopen
  4.  
  5. import bs4
  6.  
  7.  
  8. class Stimme(StrEnum):
  9.     ja = "Ja"
  10.     nein = "Nein"
  11.     na = "Nicht abg."
  12.     enthalten = "Enthalten"
  13.  
  14.  
  15. def get_abstimmung(id):
  16.     base_url = "https://www.bundestag.de/apps/na/na/namensliste.form"
  17.     query = {
  18.         "id": id,
  19.         "ajax": True,
  20.         "letter": "",
  21.         "bundesland": "",
  22.         "plz": "",
  23.         "geschlecht": "",
  24.         "alter": "",
  25.         "limit": "",
  26.     }
  27.     url = base_url + urlencode(query)
  28.     bs = bs4.BeautifulSoup(
  29.         urlopen(url),
  30.         "html.parser",
  31.     )
  32.     for match in bs.find_all("div", attrs={"class": "bt-teaser-person-text"}):
  33.         name = match.find("h3").text.strip()
  34.         fraktion = match.find("p", attrs={"class": "bt-person-fraktion"}).text.strip()
  35.         stimme = (
  36.             match.find("p", attrs={"class": "bt-person-abstimmung"})
  37.             .text.strip()
  38.             .splitlines()[0]
  39.         )
  40.  
  41.         yield name, fraktion, Stimme(stimme)
  42.  
  43.  
  44. abstimmung_atomgesetz = list(get_abstimmung(847))
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement