-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_http_requests.py
More file actions
38 lines (29 loc) · 1.32 KB
/
python_http_requests.py
File metadata and controls
38 lines (29 loc) · 1.32 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
__author__ = 'k22li'
import requests
from xml.etree import ElementTree
def requestNewUrl():
urlLink = raw_input('Kindly provide the url address to sync: ')
req = requests.get(urlLink)
if not req.status_code == 200:
print 'failed to request the url page: %s'%urlLink
return req.text, req.encoding
def xmlParseDownloadedPages(strings, encodingMethod):
if not isinstance(strings, unicode):
print 'not this string is encoded via utf-8'
strings = strings.decode(encodingMethod) # decode the dumped contents via the encoding methods
strings = strings.encode('utf-8')
else:
print encodingMethods
print 'validate if the string dumped belongs to unicode instance or not: ', isinstance(strings, unicode)
print 'check if the content is kind of string or not: ', isinstance(strings, str)
strings = strings.encode('utf-8')
print 'check if the content is kind of string or not: ', isinstance(strings, str)
print strings
# strings = strings.decode(encodingMetho)
tree = ElementTree.fromstring(strings)
print tree.tag
# print tree.getroot()
# tree.getroot()
# print ElementTree.iselement(tree)
urlContent, encodingMethods = requestNewUrl()
xmlParseDownloadedPages(urlContent, encodingMethods)