-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScrapeUrlTable2Pandas.py
More file actions
104 lines (83 loc) · 2.76 KB
/
ScrapeUrlTable2Pandas.py
File metadata and controls
104 lines (83 loc) · 2.76 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
from decorator import decorator
import sys
import pandas as pd
import requests
import lxml.html as lh
@decorator
def on_start(func,*args, **kwargs):
if kwargs !={}:
try:
if kwargs['Start']:
if 'Verbose' in kwargs['Settings']:
if kwargs['Settings']['Verbose']:
print(func)
pass
response= func(*args,**kwargs)
return response
else:
kwargs['Start'] = False
print(func,"DID NOT START")
return(kwargs)
except Exception as e:
print('NODE ERROR OCCURED TRYING TO START NODE FUNCTION:')
print('===========================================')
print(func,e)
print('===========================================')
print('LAST STATE SET TO:')
print('===========================================')
print('ekwargs')
print('===========================================')
print('LAST NODE FUNCTION SET TO:')
print('===========================================')
print('efunc')
print('===========================================')
global ekwargs
global efunc
ekwargs = kwargs
efunc = func
print('HALTING')
raise
else:
print('Empty kwargs')
return ()
def start():
return {'Start':True,'Settings':{'Verbose':True},'Status':{}}
@on_start
def lxmlParseUrl1(*args,**kwargs):
page = requests.get('https://www.w3schools.com/html/html_tables.asp')
kwargs['Data'] = lh.fromstring(page.content)
return kwargs
@on_start
def lxmlFindAll2(*args,**kwargs):
kwargs['Data'] = kwargs['Data'].get_element_by_id('customers')
return kwargs
@on_start
def lxmlTable2Pandas3(*args,**kwargs):
kwargs['Data']=pd.read_html(lh.tostring(kwargs['Data']))[0]
print(kwargs['Data'])
return kwargs
@on_start
def pandaExcelDump(*args,**kwargs):
kwargs['Data'].to_excel(''+'test.xlsx')
return kwargs
@on_start
def stop(*args,**kwargs):
print('exiting')
sys.exit()
class StremeNode:
def __init__(self):
pass
def run(self,*args,**kwargs):
self.kwargs=stop(**pandaExcelDump(**lxmlTable2Pandas3(**lxmlFindAll2(**lxmlParseUrl1(**kwargs)))))
return (self.kwargs)
class liveprocess:
def __init__(self):
self.status="pending"
def run(self,expname):
self.response=stop(**pandaExcelDump(**lxmlTable2Pandas3(**lxmlFindAll2(**lxmlParseUrl1(**start())))))
self.status="completed"
return(self.status)
if __name__ == '__main__':
process = liveprocess()
process.run('Local')