-
Notifications
You must be signed in to change notification settings - Fork 31
/
lookup-test.py
61 lines (46 loc) · 1.48 KB
/
lookup-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# this script tests the country name lookup module against several
# common country lists to test results
import wbgapi as wb
from pyquery import PyQuery
def report(url, names):
print('\nResults for {}\n'.format(url))
wb.economy.coder.report(wb.economy.coder.lookup(names))
# scrape a list of UN member states
member_names = []
url = 'https://www.un.org/en/member-states/'
doc = PyQuery(url, verify=False)
for elem in doc('span.member-state-name'):
if len(elem.text):
member_names.append(elem.text)
report(url, member_names)
# IBRD Membership
ibrd_names = []
url = 'https://www.worldbank.org/en/about/leadership/members'
doc = PyQuery(url)
for elem in doc('.tabcontent0 b'):
if elem.text:
ibrd_names.append(elem.text)
report(url, ibrd_names)
# Brittanica
url = 'https://www.britannica.com/topic/list-of-countries-1993160'
doc = PyQuery(url)
brit_names = []
for elem in doc('section li a'):
if elem.text:
brit_names.append(elem.text)
report(url, brit_names)
# Countries of the World
url = 'https://www.countries-ofthe-world.com/all-countries.html'
doc = PyQuery(url, headers={'user-agent': 'Mozilla'})
cow_names = []
for elem in doc('#content .list-container li'):
if len(elem.text) > 1:
cow_names.append(elem.text)
report(url, cow_names)
# DFA
url = 'https://www.dfa.ie/travel/travel-advice/a-z-list-of-countries/'
doc = PyQuery(url)
dfa_names = []
for elem in doc('#countriesbox a'):
dfa_names.append(elem.text)
report(url, dfa_names)