Change language

Extracting text from Wikipedia infobox in Python

Thus, the information block Wikipedia — it is a fixed-format table, usually added in the upper-right corner of articles to represent summary articles for that wiki page and sometimes to improve navigation to other related articles. 
[To learn more about infobox, click here ]

Requests" — is an Apache2 HTTP license library written in Python. Requests will allow you to send HTTP / 1.1 requests using the Python language. With it, you can add content such as headers, form data, multipart files, and parameters through simple Python libraries. It also allows you to access Python response data in the same way. 
For more information on this,
click here

I used Python 2.7 is here,

Make sure these modules are installed on your machine.
If not, then at the console or prompt, you can install it using pip

# importing modules

import requests

from lxml import etree

 
# manually save the desired URL

url = https://en.wikipedia.org/wiki/Delhi_Public_School_Society

  
# fetching its URL through the request module

req = requests.get (url) 

  

store = etree.fromstring (req.text)

 
# this will give the motto part above
# Wikipedia page URL info box

output = store.xpath ( ’ // table [@ class = "infobox vcard"] / tr [th / text () = "Motto"] / td / i’

 
# print part of the text

print output [ 0 ]. text 

 
# Run this program with Python installed or
# on your local system using cmd or any IDE.

Look at this link, it will display the Motto section of the informational page of this wikipedia (as shown in (see this screenshot). 

Write your code first

Now, finally, after starting the program, you get

You can also change the URL and store.xpath to get different sections of the infobox. 
If you would like to learn more about web scrubbing, follow these links,
1) Web Scraping 1
2) Web Scraping 2

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method