0

I have a table with stats about a match. I have extracted the tables and I can get all the different fields from the table.

I would like to do something like this:

|__Team Name
|__Logo
|__Players
   |___Different Players and their stats

I would like to know how to combine and yield these classes. So that Team class has all the players and Player class has it's individual stats '''python

class Team(scrapy.Item):

    Team_name = scrapy.Field()
    Logo = scrapy.Field()
    # Other Fields
    #Players = all the players
class Player(scrapy.Items):

    Shots = scrapy.Items()
    Assists = scrapy.Items()
    # Other Fields

I am scraping the table from "https://www.hltv.org/stats/matches/mapstatsid/90415/trz-vs-eox"

Note: I want to configure my pipeline so that I can run scrapy crawl genspider -o (file of players with a column of which team they belong) and similarly scrapy crawl genspider -o (file with team with a 5 columns as P1,P2,P3 with players of the team too

glory9211
  • 741
  • 7
  • 18
  • I don't want Team class to have a list or dict. I want to have Player class objects connected to Teams so if I export Teams it exports Players with it and if I export player it also exports it's respective Team attributes – glory9211 Aug 18 '19 at 05:49
  • ***"I don't want Team class to have a list or dict"***: So you can't fulfill your ***"So that Team class has all the players"*** – stovfl Aug 18 '19 at 05:51
  • My confusion is basically with how to use yield from my spider and put data in two different classes – glory9211 Aug 18 '19 at 05:53
  • Right now my working implementation is the same as you suggest. One class with player stats dic – glory9211 Aug 18 '19 at 05:55
  • I see, do you know the `Team` at the point you yield a new `Player`? – stovfl Aug 18 '19 at 05:56
  • Yes. The team name is in the header and the rows are player name and respective stats – glory9211 Aug 18 '19 at 05:56
  • Create a `Player` object and do `.append()`. You have to implement `def append(...` in your `class Team`. – stovfl Aug 18 '19 at 05:59
  • When exporting wouldn't it say Player object at '''""" in the file. Is there a way to set my pipeline so that when I export Team it exports players_names in the team. When I export Player it adds Team_name automatically – glory9211 Aug 18 '19 at 08:27
  • Possible duplicate of [how to implement nested item in scrapy?](https://stackoverflow.com/questions/11184557/how-to-implement-nested-item-in-scrapy) – Gallaecio Aug 19 '19 at 13:35

0 Answers0