Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import pandas as pd
- # Fetch "Pokémon"-ability information from PokemonDB
- URL = "https://pokemondb.net/ability"
- response = requests.get(URL)
- # Initialize parser
- soup = BeautifulSoup(response.content, 'html.parser')
- # Find data-table storing all abilities along with their descriptions
- table = soup.find(attrs={"class" : "data-table"})
- # Store all rows of table in a list, skip header
- rows = table.find_all("tr")[1:]
- # Iterate through all rows, find all cells, store their text contents as a list entry
- entries = [[entry.text for entry in row.find_all("td")] for row in rows]
- # Create dataframe from 2d-array "entries"
- df = pd.DataFrame(entries, columns=["Name", "Pokémon", "Description", "Generation"])
- # Drop columns "Pokémon" and "Generation"
- df.drop(["Pokémon", "Generation"], axis=1, inplace=True)
- # Fill out missing description entry of ability "Quick Draw"
- df.Description.iloc[185] = "Enables the Pokémon to move first occasionally."
- df.to_csv("dataClean/Abilities.csv")
Advertisement
Add Comment
Please, Sign In to add comment