티스토리 뷰

 

 

def GetItemValue(self, elemIn, paramIn):
        # paramIn :  ItemValue or ValueTag : {‘TagProperty’, ‘TagType’, ‘TagValue’, ‘valueTag_s’, [‘Attribute’]}
        tagType = paramIn.get('TagType')
        tagValue = paramIn.get('TagValue')
        tagProperty = paramIn.get('TagProperty')
        valueID = paramIn.get('ValueID')
        attrib = paramIn.get('Attribute')
        subTags = paramIn.get('SubTag_s')
        valueTags = paramIn.get('ValueTag_s')

        rst1 = {}
        if valueID: # tagProperty == "aValue"
            elem1 = self.GetElement(elemIn, tagType, tagValue)
            if not elem1:
                return
            if not attrib:
                rst1[valueID] = elem1.text
            elif attrib=="text":
                #print("[elem1]", str(elem1))
                rst1[valueID] = elem1.text
            else:
                rst1[valueID] = elem1.get_attribute(attrib)
                #print("[text]", elem1.get_attribute('innerHTML'))
            return rst1

        if subTags:
            rst1DF = DataFrame()
            elem1 = self.GetElement(elemIn, tagType, tagValue)
            if str(type(subTags))=="<class 'list'>":
                for subTag in subTags:
                    res1 = self.GetItemValue(elem1, subTag)
                    if not res1.empty:
                        #print("[res1]", res1)
                        if rst1DF.empty: rst1DF = DataFrame(res1)
                        else: rst1DF = rst1DF.append(res1, ignore_index=True)
            elif str(type(subTags))=="<class 'dict'>":
                res1 = self.GetItemValue(elem1, subTags)
                if not res1.empty: 
                    #print("[res1]", res1)
                    if rst1DF.empty: rst1DF = DataFrame(res1)
                    else: rst1DF = rst1DF.append(res1, ignore_index=True)
            else:
                print("[?] Wrong Type of SubTags")

            return rst1DF


        if tagProperty=="ItemValue":
            if not valueTags:
                print("[?] None of ValueTags")
                return
            for valueTag in valueTags:
                try:
                    res1 = self.GetItemValue(elemIn, valueTag)
                    if res1: 
                        #print("[res1]", res1)
                        if rst1: rst1.update(res1)
                        else: rst1 = res1.copy()
                except Exception as e:
                    print("[???] ", str(e))
                    continue
            return DataFrame([rst1])
        elif tagProperty=="ItemValues":
            elems1 = self.GetElements(elemIn, tagType, tagValue)
            for elem11 in elems1:
                for valueTag in valueTags:
                    try:
                        res1 = self.GetItemValue(elemIn, valueTag)
                        if res1: 
                            #print("[res1]", res1)
                            if rst1: rst1.update(res1)
                            else: rst1 = res1.copy()
                    except Exception as e:
                        print("[???] ", str(e))
                        continue

            return DataFrame([rst1])

        return DataFrame()

 

반응형

'SWDesk' 카테고리의 다른 글

[Python] PickNewItems - TreatPage()  (0) 2022.05.29
[Python] PickNewItems - TreatSubTag()  (0) 2022.05.28
[Python] Data Addition after Initialization  (0) 2022.05.23
[Python] Stock Trade  (0) 2022.04.12
BStockTrade - DataManager  (1) 2022.03.15