[Python] DataFrame - Dict - json
[siteInfo example]
{'Description': '향고래 > 알', 'I_Date': '2022-05-26 9:16:46', 'ItemTag': '{"TagProperty": "Bundle", "TagType": "class", "TagValue": ".product", "SubTag_s": {"TagProperty": "Items", "TagType": "html", "TagValue": "li", "SubTag_s": {"TagProperty": "ItemValue", "TagType": "class", "TagValue": ".prdInfo", "ValueTag_s": [{"TagProperty": "aValue", "TagType": "html", "TagValue": "a", "Attribute": "href", "ValueID": "ItemLink"}, {"TagProperty": "aValue", "TagType": "html", "TagValue": "a", "Attribute": "text", "ValueID": "Title"}, {"TagProperty": "aValue", "TagType": "class", "TagValue": ".price", "Attribute": "text", "ValueID": "Price"}, {"TagProperty": "aValue", "TagType": "html", "TagValue": "p", "Attribute": "text", "ValueID": "Description"}, {"TagProperty": "aValue", "TagType": "class", "TagValue": ".Icon", "Attribute": "text", "ValueID": "Status"}]}}}', 'L_Date': '2022-07-14 0:51:58', 'L_Status': '0', 'PageTag': '{"TagType": "class", "TagValue": ".pageArea", "SubTag_s": [{"TagProperty": "PageNo", "TagType": "html", "TagValue": "a"}, {"TagProperty": "PageNo", "TagType": "html", "TagValue": "b"}], "StartPage": 1}', 'SiteID': 'Sinyoung-01', 'SiteURL': 'http://al.hyang.whale/bbs/board.php?tbl=product_03&category=%EB%B9%84%EC%83%81%EC%A1%B0%EB%AA%85%EB%93%B1', 'Status': 'Valid'}
from BGoogleDrive import cBGoogleSpread
import json
gSpread = cBGoogleSpread()
SourceSpread = gSpread.OpenSpreadsheet("NIP_Source")
siteInfosDF = gSpread.ReadSheet(SourceSpread, "SiteInfo")
siteInfoList = siteInfosDF.to_dict('records')
for siteInfo in siteInfoList:
# siteInfo example : {'Description': '향고래 > 알', 'I_Date': '2022-05-26 9:16:46', 'ItemTag': '{"TagProperty": "Bundle", "TagType": "class", "TagValue": ".product", "SubTag_s": {"TagProperty": "Items", "TagType": "html", "TagValue": "li", "SubTag_s": {"TagProperty": "ItemValue", "TagType": "class", "TagValue": ".prdInfo", "ValueTag_s": [{"TagProperty": "aValue", "TagType": "html", "TagValue": "a", "Attribute": "href", "ValueID": "ItemLink"}, {"TagProperty": "aValue", "TagType": "html", "TagValue": "a", "Attribute": "text", "ValueID": "Title"}, {"TagProperty": "aValue", "TagType": "class", "TagValue": ".price", "Attribute": "text", "ValueID": "Price"}, {"TagProperty": "aValue", "TagType": "html", "TagValue": "p", "Attribute": "text", "ValueID": "Description"}, {"TagProperty": "aValue", "TagType": "class", "TagValue": ".Icon", "Attribute": "text", "ValueID": "Status"}]}}}', 'L_Date': '2022-07-14 0:51:58', 'L_Status': '0', 'PageTag': '{"TagType": "class", "TagValue": ".pageArea", "SubTag_s": [{"TagProperty": "PageNo", "TagType": "html", "TagValue": "a"}, {"TagProperty": "PageNo", "TagType": "html", "TagValue": "b"}], "StartPage": 1}', 'SiteID': 'Sinyoung-01', 'SiteURL': 'http://al.hyang.whale/bbs/board.php?tbl=product_03&category=%EB%B9%84%EC%83%81%EC%A1%B0%EB%AA%85%EB%93%B1', 'Status': 'Valid'}
keys1 = siteInfo.keys()
for key1 in keys1:
print("[Key] ", key1)
print("[Value]", siteInfo[key1])
pageTag_ = siteInfo.get('PageTag')
pageTag = json.loads(pageTag_)
print("[Type]", type(pageTag))
#valueTags = json
#keys2 = pageTag.keys()
for key2 in pageTag.keys():
print("[Key2]", key2)
print("[ValueTag2]", pageTag[key2])
subTags2 = pageTag['SubTag_s']
for subTag in subTags2:
print(subTag)
print(siteInfo)