'How to scrape data from wikipedia list into pandas dataframe
I'm trying to scrape a list, not a table, from a wikipedia page. It says "list index out of range": how can I solve this?
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = 'https://it.m.wikipedia.org/wiki/Premio_Bagutta'
data = requests.get(url)
soup= BeautifulSoup(data.content, "html.parser")
raw = soup.find_all("div", {"class": "div-col"})[0].find_all("li")
df = pd.DataFrame([[item.get_text().split(" ")[0],
item.find_next("a").get("title"),
item.find_next("i").get_text()[1:-1]]
for item in raw if item.find_next("i")],
columns=("Year"))
print(df.head())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
