Skip to content

Instantly share code, notes, and snippets.

@voigtjessica
Created January 12, 2022 17:16
Show Gist options
  • Save voigtjessica/1b87c44572553063d3ddf63110a4723d to your computer and use it in GitHub Desktop.
Save voigtjessica/1b87c44572553063d3ddf63110a4723d to your computer and use it in GitHub Desktop.
Raspagem munic NRW
Display the source blob
Display the rendered blob
Raw
import requests
import pandas as pd
import janitor
from bs4 import BeautifulSoup
url = 'https://www.nrw-live.de/staedte-nrw'
req = requests.get(url)
soup = BeautifulSoup(req.content, 'html5lib')
list_stadt_nrw = soup.findAll('a')
list_stadt_nrw # retornou uma lista para cara <a>
len(list_stadt_nrw)
#onde começa e onde terminam as cidades:
list_stadt_nrw[87].text # start in 87 = 'Aachen'
list_stadt_nrw[482].text # ends here = 'Zülpich'
stadt_nrw = []
for i in range(87, 482):
t = list_stadt_nrw[i].text
stadt_nrw.append(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment