Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get table wikipedia

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))
Comment

PREVIOUS NEXT
Code Example
Python :: Python NumPy array_split Function Syntax 
Python :: how to find duplicates in csv file using python 
Python :: apply 2d mask to 3d array python 
Python :: Proj 4.9.0 must be installed. 
Python :: model.predict python 
Python :: remove punctuation 
Python :: create QAction with icon in pyqt 
Python :: assert with message python 
Python :: input lstm 
Python :: python for in range 
Python :: how to devided array into parts python 
Python :: image processing python 
Python :: Python Renaming a Directory or a File 
Python :: pandas python example 
Python :: python convert string to float 
Python :: numpy maximum 
Python :: tuple to string python 
Python :: Reverse an string Using Loop in Python 
Python :: python int to byte 
Python :: use argparse to call function and use argument in function 
Python :: turn string into operator python 
Python :: install python package 
Python :: python request body json 
Python :: how to run class.function from name python 
Python :: lcd of 18 and 21 
Python :: search in django 
Python :: double for loop in list comprehension 
Python :: padnas check if string is in list of strings 
Python :: count in python 
Python :: negative slicing in python list 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =