-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp.py
More file actions
68 lines (50 loc) · 1.56 KB
/
exp.py
File metadata and controls
68 lines (50 loc) · 1.56 KB
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
62
63
64
65
#this script gets info about the christiano ronaldo from wikipedia
from lxml import html
import requests
import sys
import calendar
print 'tell me the birth date in ddmmyyy format'
# full_date = raw_input()
# if len(full_date) != 8:
# print 'date is in wrong format'
# sys.exit()
# day = int(full_date[0] + full_date[1])
# month = int(full_date[2] + full_date[3])
# year = int(full_date[4] + full_date[5] + full_date[6] + full_date[7])
# event_month = 0
# if month<10:
# year = year -1
# event_month = month - 9 +12
# else:
# event_month = month - 9
# monthname = calendar.month_name[event_month]
#getting data from wiki page
# page = requests.get('https://en.wikipedia.org/wiki/' + str(year))
page = requests.get('https://en.wikipedia.org/wiki/%s' % str(1965) )
#creating XPath tree out of it
tree = html.fromstring(page.content)
#parsing the tree
# visit http://www.w3schools.com/xsl/xpath_nodes.asp for syntaxes
# for specifying address of a tree node
#reaching january 4
# monthday = str(monthname + " " + str(day))
# print monthday
input_data = '//ul[following-sibling::h2[child::span[@id = "Births"]]]/li[child::a[@title = "January 4"]]//text()'
event = tree.xpath(input_data)
print event
# str_of_event = ""
# # getting data out of event
# for tagn in range(2,len(event)):
# try:
# tag_data = str(event[tagn])
# if "\n" in tag_data:
# break
# if monthday in tag_data:
# break
# str_of_event = str_of_event + tag_data
# except UnicodeEncodeError:
# continue
# if str_of_event is "":
# print "no record found"
# else:
# print str_of_event