dear community - fellow python-experts,
've been trying to scrape a table on Wikipedia using Beautifulsoup, but encountered some problems.
well the very first step is - i guess to check the table on the wikipage,
The classes are wikitable collapsible - that are collapsed mw-collapsible:
Well - there's no sortable class in there. We need to find out the matching table element.
The question is: how do I correctly point towards that table?
i need to hook up to some unique identifier, such as an id of the element.
Have had a look at the DOM tree, and check its parents - and if there is any unique identifier.
If i do it like so:
Well i am asking this since i am not very familiar with pandas.
look forward to hear from you

've been trying to scrape a table on Wikipedia using Beautifulsoup, but encountered some problems.
well the very first step is - i guess to check the table on the wikipage,
The classes are wikitable collapsible - that are collapsed mw-collapsible:
Well - there's no sortable class in there. We need to find out the matching table element.
The question is: how do I correctly point towards that table?
i need to hook up to some unique identifier, such as an id of the element.
Have had a look at the DOM tree, and check its parents - and if there is any unique identifier.
If i do it like so:
import requests from bs4 import BeautifulSoup URL = "https://en.wikipedia.org/wiki/List_of_current_heads_of_state_and_government" res = requests.get(URL).text soup = BeautifulSoup(res,'lxml') for items in soup.find('table', class_='wikitable').find_all('tr')[1::1]: data = items.find_all(['th','td']) try: country = data[0].a.text title = data[1].a.text name = data[1].a.find_next_sibling().text except IndexError:pass print("{}|{}|{}".format(country,title,name))well this is a way - and this leads to the results as seen here
Algeria|President|Abdelaziz Bouteflika Andorra|Episcopal Co-Prince|Joan Enric Vives Sicília Angola|President|João Lourençowell this is one way _ but i think it is much much smarter to use pandas' and to put the data into a dataframe.
Well i am asking this since i am not very familiar with pandas.
look forward to hear from you
