循环遍历表并在scrapy中添加某些元素

toiithl6  于 2023-08-05  发布在  其他
关注(0)|答案(1)|浏览(126)

我有下面的scrapy代码,从URL中提取信息:
[https://www.fcf.cat/acta/2223/futbol-11/divisio-honor-cadet/grup-1/hc/barcelona-fc-a/hc/damm-cf-a][1]

team1_data = {}
    for table in cols[0].css(".acta-table"):
            # extract the table heading
            table_heading = table.css("thead th::text").get()
            table_data = {} # data for this table
            
            if table_heading == "Equip Tècnic":
                # coach data
                table_data = [] # change to list

                for row in table.css("tbody tr"):
                    table_data.append(
                        row.css("td.tc::text").get()
                    )
            else:
                # players data
                for row in table.css("tbody tr"):
                    
                    player_number = row.css("span.num-samarreta-acta2::text").get()
                    player_name = row.css("td a::text").get()

                    table_data[player_number] = player_name
                    

            # add to team data
            team1_data[table_heading] = table_data

字符串
我想一些帮助添加在预订的情况下提取适当的代码,预订类型和分钟。
谢啦,谢啦

mfpqipee

mfpqipee1#

我已经想好了:

player_number = row.css("span.num-samarreta-acta2::text").get()
                        player_name = row.css("td a::text").get()

                        timestamp_acta = ""
                        targeta = ""
                        

                        if row.css(".acta-minut-targeta"):
                            timestamp_acta = row.css(".acta-minut-targeta::text").get()
                        
                        if row.css(".groga-s"):
                            targeta = "groga"
                        
                        if row.css(".vermella-s"):
                            targeta = "vermella"
                        #timestamp_acta = row.css("td:acta-minut-targeta::text").get()
                        
                        if timestamp_acta == "":
                            table2_data[player_number] = player_name
                        else:
                            # table_data[player_number] = player_name
                            # table_data["Targeta"] = targeta
                            # table_data["Minut"] = timestamp_acta   
                            table2_data[player_number] = {
                                "Nom": player_name,
                                "Minut": timestamp_acta,
                                "Targeta": targeta
                            }

字符串

相关问题