Problem
I have various html tables that I need to parse/access from my customers web-page, the data on it might vary across the tables (length of columns).
So, what I've done was to create a class for each table but this task became ridiculous, since there are a lot of tables that I need to parse with data varying.
Question
Is there any way to implement DTOs in python other than creating a class for each data that I what to transfer?
Example
Class
class HoldItem():
@property
def none1(self):
return self
@property
def none2(self):
return self
@property
def item(self):
return self
@property
def plant(self):
return self
@property
def location(self):
return self
@property
def material(self):
return self
@none1.setter
def none1(self, value):
self.none1 = value
Populate Instances
items = []
for tds in trs:
item = HoldItem()
if (x == PROP_A):
item.prop_a = tds.InnerText
...
...
...
items.append(item)
return items
Transfer to SQLServer Database
for item in items:
command.AddWithValue("@prop_a", item.prop_a)
Facts
- I'm using Iron Python
- I'm transfering the information into a table (SQL Server)
- I'm using HtmlAgilityPack in order to parse the html table
- I'm web-crawling the page